#cant crack my error

18 messages · Page 1 of 1 (latest)

fossil cliff
#

The cost to ship a package is a flat fee of 75 cents plus 25 cents per pound.

  1. Declare a constant named CENTS_PER_POUND and initialize with 25.
  2. Get the shipping weight from user input storing the weight into shipWeightPounds.
  3. Using FLAT_FEE_CENTS and CENTS_PER_POUND constants, assign shipCostCents with the cost of shipping a package weighing shipWeightPounds.

public class ShippingCalculator {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int shipWeightPounds;
int shipCostCents = 0;
final int FLAT_FEE_CENTS = 75;

final int CENTS_PER_POUND = 25;

Scanner sr=new Scanner(System.in);

System.out.print("Enter the shipping weight:");

System.out.println("shipping Weight: " + shipWeightPounds);

 System.out.println("flat fee of shipping in cents : " + FLAT_FEE_CENTS);

 System.out.println("Cents/pound for shipping: " + CENTS_PER_POUND);

System.out.println("total cost of shipping in cents: " + shipCostCents);



  System.out.println("Weight(lb): " + shipWeightPounds);
  System.out.println("Flat fee(cents): " + FLAT_FEE_CENTS);
  System.out.println("Cents per pound: " + CENTS_PER_POUND);
  System.out.println("Shipping cost(cents): " + shipCostCents);

}
}
my code so far

tribal archBOT
#

This post has been reserved for your question.

Hey @fossil cliff! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

#
import java.util.Scanner;

public class ShippingCalculator {
	public static void main(String[] args) {
		Scanner scnr = new Scanner(System.in);
		int shipWeightPounds;
		int shipCostCents = 0;
		final int FLAT_FEE_CENTS = 75;
		
		final int CENTS_PER_POUND = 25;
		
		Scanner sr=new Scanner(System.in);
		
		System.out.print("Enter the shipping weight:");
		
		System.out.println("shipping  Weight: " + shipWeightPounds);
		
		System.out.println("flat fee of shipping in cents : " + FLAT_FEE_CENTS);
		
		System.out.println("Cents/pound for shipping: " + CENTS_PER_POUND);
		
		System.out.println("total cost of shipping in cents: " + shipCostCents);
		
		
		
		System.out.println("Weight(lb): " + shipWeightPounds);
		System.out.println("Flat fee(cents): " + FLAT_FEE_CENTS);
		System.out.println("Cents per pound: " + CENTS_PER_POUND);
		System.out.println("Shipping cost(cents): " + shipCostCents);
	}
}
my code so far
dusty rapids
#

I mean there isn't really any logic done so far. Just print statements for now

fossil cliff
#

the error code i keep getting shows shipWeightpounds on line 16 is the error but i dont know why

dusty rapids
#

because it isn't initialized yet

#

you are just declaring it. Basically telling the compiler, "hey reserve some space for this variable". But the compiler doesn't know what you want from it when asking "hey, what are the contents of that variable".

fossil cliff
#

so i havent given it a task to run so to speak but now im more confused on how to give it said task

dusty rapids
#

Its already running. You are just not doing anything yet.
First of all initialize the shipWightPounds variable to something for example 0.
Then use the scanner to get input from the user and finally calculate the cost.

fossil cliff
#

So i tried to write a line to set the weight at zero like you suggested and it said the weight was already calculated but the when I take the new line out it keeps showing line 16 is my error

dusty rapids
#

so what I expect is either:

...
int shipWeightPounds = 0;
...

or

...
int shipWeightPounds = sr.nextInt(); 
or int shipWeightPounds = Integer.parseInt(sr.next()); 
or int shipWeightPounds = Integer.parseInt(sr.nextLine());
...
fossil cliff
#

error: variable shipWeightPounds is already defined in method main(String[]

#

this the error message now

dusty rapids
#

yeah don't define the variable twice

#

just once somewhere in your main method

fossil cliff
#

I found where it defined it and then i corrected it now shes running thanks a million mate

tribal archBOT