Guest User

Grocery2

a guest
Oct 27th, 2012
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.82 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Grocery2
  4. {
  5.  public static void main(String[] args)
  6.  {
  7.         //Setup
  8.         double Total, grocprice1 = 0, grocprice2 = 0, grocprice3 = 0; // Totals
  9.  
  10.         double prcApple = .30;
  11.         double prcOrange = .45;
  12.         double prcStrawberry = 2.30;
  13.         double prcPotato = 3.25;
  14.         double prcTurnips = .70;
  15.         double prcCarrots = 1.25;
  16.  
  17.         Scanner scanner = new Scanner(System.in);
  18.  
  19.         //Screen Input
  20.         //Enter Name
  21.         System.out.println("Enter your full name:");
  22.         String fullname = scanner.nextLine();
  23.  
  24.         //Enter Address
  25.         System.out.println("Enter your Address");
  26.         String address = scanner.nextLine();
  27.  
  28.         //Enter Credit Card Number
  29.         System.out.println("Enter your Credit Card Number");
  30.         String creditcard = scanner.nextLine();
  31.  
  32.         //Enter Date Of Birth
  33.         System.out.println("Enter your Date of Birth");
  34.         String dob = scanner.nextLine();
  35.  
  36.         //Enter Email Address
  37.         System.out.println("Enter your Email Address");
  38.         String emailaddr = scanner.nextLine();
  39.  
  40.         //Re-Enter Email Address
  41.         System.out.println("Re-Enter your Email Address");
  42.         String emailaddr2 = scanner.nextLine();
  43.  
  44.         //Enter First Grocery Item
  45.         System.out.println("Enter the first grocery item ");
  46.         String grc1 = scanner.nextLine();
  47.  
  48.         //Enter first quantity
  49.         System.out.println("How many of these would you like");
  50.         int qty1 = Integer.valueOf(scanner.nextLine());
  51.  
  52.        if(grc1.equals("Apples"))
  53.         {
  54.             grocprice1 = prcApple * qty1;
  55.         }
  56.         else if(grc1.equals("Oranges"))
  57.         {  
  58.                 grocprice1 = prcOrange * qty1;
  59.         }
  60.         else if (grc1.equals("strawberries"))
  61.         {
  62.                 grocprice1 = prcStrawberry * qty1;
  63.         }
  64.         else if (grc1.equals("Potatoes"))
  65.         {
  66.                 grocprice1 = prcPotato * qty1;
  67.         }
  68.         else if (grc1.equals("Turnips"))
  69.         {
  70.                 grocprice1 = prcTurnips * qty1;
  71.         }
  72.         else if (grc1.equals("Carrots"))
  73.         {
  74.                 grocprice1 = prcCarrots * qty1;
  75.         }
  76.      
  77.  
  78.  
  79.  
  80.  //Enter second Grocery Item
  81.  System.out.println("Enter the second grocery item ");
  82.  String grc2 = scanner.nextLine();
  83.  
  84.  //Enter second quantity
  85.  System.out.println("How many of these would you like");
  86.  int qty2 = Integer.valueOf(scanner.nextLine());
  87.  
  88. if (grc2.equals("Apples"))
  89.  {
  90.     grocprice2 = prcApple * qty2;
  91.  }
  92. else if (grc2.equals("Oranges"))
  93.  {
  94.     grocprice2 = prcOrange * qty2;
  95.  }
  96. else if (grc2.equals("strawberries"))
  97.  {
  98.     grocprice2 = prcStrawberry * qty2;
  99.  }
  100. else  if (grc2.equals("Potatoes"))
  101.  {
  102.     grocprice2 = prcPotato * qty2;
  103.  }
  104. else  if (grc2.equals("Turnips"))
  105.  {
  106.     grocprice2 = prcTurnips * qty2;
  107.  }
  108. else  if (grc2.equals("Carrots"))
  109.  {
  110.      grocprice2 = prcCarrots * qty2;
  111.  }
  112.  
  113.  //Enter third Grocery Item
  114.  System.out.println("Enter the third grocery item ");
  115.  String grc3 = scanner.nextLine();
  116.  
  117.  //Enter third quantity
  118.  System.out.println("How many of these would you like");
  119.  int qty3 = Integer.valueOf(scanner.nextLine());
  120.  
  121. if (grc3.equals("Apples"))
  122.  {
  123.  grocprice3 = .60 * qty3;
  124.  }
  125. else  if (grc3.equals("Oranges"))
  126.  {
  127.     grocprice3 = prcOrange * qty3;
  128.  }
  129. else  if (grc3.equals("strawberries"))
  130.  {
  131.     grocprice3 = prcStrawberry * qty3;
  132.  }
  133. else if (grc3.equals("Potatoes"))
  134.  {
  135.     grocprice3 = prcPotato * qty3;
  136.  }
  137. else  if (grc3.equals("Turnips"))
  138.  {
  139.      grocprice3 = prcTurnips * qty3;
  140.  }
  141. else  if (grc3.equals("Carrots"))
  142.  {
  143.     grocprice3 = prcCarrots * qty3;
  144.  }
  145.  
  146.  /* Calculate the price */
  147.  Total = grocprice1 + grocprice2 + grocprice3;
  148.  System.out.println("Thank You "+ Total);
  149.  }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment