Then it would be
But more likely
The stuff I am confused on are:
1) the estimated method already puts that cost for each zone into estimatedPackaging variable. So I am just moving the value from one variable to another? Plus I still need to get the final cost by adding it to my getPRice, since that is what is going to return the price. So the way I am reading those instructions it looks something like:
2) Again, the addPackages does not return anything, but in main I need to output the total number of packages for each of the three shipping methods they can choose. As far as the directions go there is no getter for total packages, and all output belongs in main. So how does that work? My thought is it would be easier to create 3 variables and increment them after my if which would look like:
Here is where I am getting confused..the addPackaging does not return anything, so I cant get that total shipping cost sitting in the variable if I cant return it??
You can't add the value of a variable in to a methodcall.
It's unclear to me what you trying to do for zone 2. If you have to do the same for all if's, why bougther to make them.
Based on what I see you could change it to:
It's also unclear to me why you in your main scan for a next line after taking the int.
You als have to acount for the fact that the user could put in a different value the you expect.
Knute Snortum wrote:The other possibility is the totalShipping is declared outside of any methods and therefore is in scope in all methods. I wouldn't recommend this, but if it is "given" then you have to work with it.
In your earlier posts you can see that totalShipping is a private instance variable, so indeed accesible for all methods, but without a getter or a method that returns it, still not reachable from your main.
Here is what I have now...could be wrong, but this is what im understanding right now. So if I set totalShipping to my estimate method that is giving me just the shipping cost returned based on the zone chosen by the user? From there I add the price the user has entered giving me the total cost for everything?
And yes knute the totalShipping has a global scope
Cody Biggs wrote:Well I’m just gonna have to make it a get method and get a few points off, and see what his solution is.
You will lose points for using a getter? That doesn't sound right.
Here is what it looks like in main to get the shipping and totalcost
You're also using the formatter wrong. check this on how to use it.
As for your if statements around the shipping method, you can greatly reduce the amount of code that you write in this case by using an array of Shipper objects instead of defining three distinct variables like shipA, shipB, and shipC. Then you can define constants SHIP_STANDARD, SHIP_2ND_DAY, SHIP_EXPRESS with values that correspond to an appropriate index in the array of Shipper objects. There is nothing that I see in your requirements that won't allow you to do this, unless of course you haven't been taught to use arrays yet.
scan.useDelimeter("") and then scan.next()
Something like this would probably make more sense: