Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Calculating savings  RSS feed

 
Jack Tabby
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am very new to programming. I have a program written out to show the monthly bill of different service providers. I figured out that part, no problem. I need to calculate savings, if any, between packages A and B, B and C, as well as B and C. I have looked through my book and I can't figure it out for the life of me. I don't know what to do at this point. Any help would be greatly appreciated! I am supposed to use the Scanner class, switch statement, and if statements.
 
Jack Tabby
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if I am on the right track, but I added some to it. My program does not do what it is supposed to, but I think I am heading into the right direction?


 
Sankalp Bhagat
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your first code works fine

Which package did you purchase? Enter A, B, or C: A
How many hours did you use?: 12
Your monthly bill is $13.95


what's your exact query? You need to calculate saving between A and B, B and C, as well as B and C as per you said. so do you want your program to ask for different packages how many hours did you use one by one?
If you can, write what output you want. according to that the program should be written
 
Campbell Ritchie
Marshal
Posts: 55741
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I am afraid your question suggests to me that you are guessing. You mustn't guess. Well, you can. If you make 1000000 guesses, make sure they are all different, and there is a good chance one will be correct. Or you can work it out and get it right first time
SB suggests your first code works, but I am afraid that doesn't get you very far. You have not written object‑oriented code. You should have a Package class with a price field. You should instantiate three Package objects and get them to work out the cost of each. You should remove all that code from the main method.

I suggest you need to turn your computer off and work out with pencil and paper how you intend to calculate the charges. I see there is a formula with monthly fee, base hours and additional hours. One of the packages does not seem to have base hours, but you can easily put that in the same formula by using 0 for base hours. Or maybe 0 for charge per additional hour.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!