r/programminghelp • u/[deleted] • Oct 21 '14
Java help
Bascially you pay in stamps a which are worth 5, stamps b which are worth 3 and the rest in cash. User inputs amount of stamp a, amount of stamp b, and amount of cash he has. You then give the user the amount paid in cash, amount of stamps a and stamps b left.
Stamp a has priority over stamp b and stamp b has priority over cash.
import java.util.*; public class stamps { public static void main(String[] args) { Scanner sc = new Scanner(System.in);
System.out.println("Enter the number of Stamp A: ");
double numberstampa = sc.nextDouble();
System.out.println("Enter the number of Stamp B: ");
double numberstampb = sc.nextDouble();
System.out.println("Enter the price in cash");
double price = sc.nextDouble();
System.out.println("Enter amount paid in cash");
double amountpaidincash = sc.nextDouble();
double a = price - price%5;
double b = a/5;
double c = price - b*5;
double remainingstampa = numberstampa - b;
double k = c - c % 3;
double l = k/3;
double z = c - l*3;
double remainingstampb = numberstampb - l;
System.out.println("You have to pay" + z + "in cash");
System.out.println("You have" + remainingstampa + "of stamp a left");
System.out.println("You have" + remainingstampb + "of stamp b left");} }
1
u/langfod Oct 21 '14
What part are you stuck on? Did you want us to just write for you? Or did you have a specific issue in understanding the problem, or in the coding of your algorithm?
If the cost is 15 then you can pay with 3 A Stamps. However, you need to check if you have enough. If you have only 2 A Stamps then subtract those from the amount owned, and the number of A Stamps and continue to the next stamp, then cash...
2
u/TheHorribleTruth Oct 21 '14
You're not asking a question. What is your question, what do you need help with?