Advertisement
binibiningtinamoran

PaintCost.java

May 4th, 2020
1,989
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PaintCost {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner input = new Scanner(System.in);
  8.  
  9.         int choice;
  10.         double gallons = 0;
  11.  
  12.         do {
  13.            
  14.             System.out.print("Do you want red or green paint? Please type 1 for red or 2 for " +
  15.                     "green: ");
  16.             int paint = input.nextInt();
  17.            
  18.             while (paint != 1 && paint != 2) {
  19.                 System.out.println("Do you want red or green paint? Please type 1 for red or 2 for green");
  20.                 paint = input.nextInt();
  21.             }
  22.  
  23.             System.out.println("How many full gallons do you need?");
  24.             gallons += input.nextDouble();
  25.  
  26.             System.out.println("Do you want to make another purchase? 1. for yes 2. for no");
  27.             choice = input.nextInt();
  28.            
  29.         } while (choice == 1 ); //repeats until user wants to stop making purchases
  30.  
  31.         titleName();
  32.  
  33.         double redCost = redCalc(gallons);
  34.         double greenCost = greenCalc(gallons);
  35.  
  36.  
  37.         System.out.println("The cost of the red paint is $" + redCost);
  38.         System.out.println("The cost of the green paint is $" + greenCost);
  39.        
  40.         double totalCost = getTotalCost(redCost,greenCost);
  41.  
  42.         System.out.printf("You're total cost is $%,.2f\n.",totalCost);
  43.         thankyouMessage();
  44.  
  45.     }
  46.  
  47.     public static double redCalc(double gallons) {
  48.         return gallons * 21.95;
  49.     }
  50.  
  51.     public static double greenCalc(double gallons) {
  52.         return (gallons * 19.95);
  53.     }
  54.    
  55.     public static double getTotalCost(double a, double b) {
  56.         return (0.08 * (a+b)) + (a+b);
  57.     }
  58.  
  59.     public static void titleName() {
  60.         System.out.println("The Rainbow Paint Store");
  61.     }
  62.  
  63.     public static void thankyouMessage() {
  64.         System.out.println("Thank you for purchasing! Please come again!");
  65.     }
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement