Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class PaintCost {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int choice;
- double gallons = 0;
- do {
- System.out.print("Do you want red or green paint? Please type 1 for red or 2 for " +
- "green: ");
- int paint = input.nextInt();
- while (paint != 1 && paint != 2) {
- System.out.println("Do you want red or green paint? Please type 1 for red or 2 for green");
- paint = input.nextInt();
- }
- System.out.println("How many full gallons do you need?");
- gallons += input.nextDouble();
- System.out.println("Do you want to make another purchase? 1. for yes 2. for no");
- choice = input.nextInt();
- } while (choice == 1 ); //repeats until user wants to stop making purchases
- titleName();
- double redCost = redCalc(gallons);
- double greenCost = greenCalc(gallons);
- System.out.println("The cost of the red paint is $" + redCost);
- System.out.println("The cost of the green paint is $" + greenCost);
- double totalCost = getTotalCost(redCost,greenCost);
- System.out.printf("You're total cost is $%,.2f\n.",totalCost);
- thankyouMessage();
- }
- public static double redCalc(double gallons) {
- return gallons * 21.95;
- }
- public static double greenCalc(double gallons) {
- return (gallons * 19.95);
- }
- public static double getTotalCost(double a, double b) {
- return (0.08 * (a+b)) + (a+b);
- }
- public static void titleName() {
- System.out.println("The Rainbow Paint Store");
- }
- public static void thankyouMessage() {
- System.out.println("Thank you for purchasing! Please come again!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement