• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Total NOOB Needs Help Fast

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>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>;
 
The only taste of success some people get is to take a bite out of you. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic