wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Total NOOB Needs Help Fast Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Total NOOB Needs Help Fast" Watch "Total NOOB Needs Help Fast" New topic
Author

Total NOOB Needs Help Fast

T Hackett
Greenhorn

Joined: Jan 18, 2005
Posts: 2
I am to do an assignment for my Java class(as in school not an actual class named Java)

I need to know how to perform the following calculation

User enters a number of coffee bags

coffee bags are shipped in a specific size box based on how many bags are ordered.

Program needs to get number of bags and calculate total number of boxes needed and the total cost.

Large box holds 20 bags and the box costs 2.00
Med box holds 10 bags and costs 1.00
small box holds 5 bags and costs .50
bags cost 5.50 each

I have the jist of what to do but I can't see how to do it without a java version of V/B's "If then Else" statement.

the text hasn't covered that yet.



please help if you can, my assignment is due tomorrow. today is tuesday the jan 18, 05
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Java, as almost all programming languages, does have if and if/else statements avaiable. I'm fairly sure they would be covered in your text (at some point). You can also thake a look at the Sun's online tutorial on Control Flow Statements.

At a quick glance, using if statements is the way I would go about solving that problem. However I am curious as to why it would be presented to you prior to learning about if statements. What topics have you covered so far?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
>without a java version of V/B's "If then Else" statement

it's the same in java

double totalCost = bagsOrdered * bagCost;
if(bagsOrdered <= 5) totalCost+=.50;
else if(bagsOrdered <= 10) totalCost+=1.00;
else if(bagsOrdered <= 20) totalCost+=2.00;
else <something else goes here>;
 
wood burning stoves
 
subject: Total NOOB Needs Help Fast
 
Similar Threads
Help with using Buffered Reader and if statements
Beginner Mistake I bet you get this 100 times a year
Simple Calculator help
calculating number of days
classes and methods