Advertisement
Excitium

CarpetDriverMiller.java

Apr 18th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.60 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CarpetDriverMiller{
  4.  
  5.     static  Scanner reader = new Scanner (System.in);
  6.     static  Carpet[] quote = new Carpet[20];
  7.     static int counter = 0;
  8.  
  9.     public static void main (String args []){
  10.         int choice;
  11.  
  12.         while(true){
  13.             choice = menu();
  14.             if(choice == 1){
  15.                 setGenericQuote();
  16.             }else if(choice == 2){
  17.                 setCustomQuote(0, getAddress());    //you may use either a String
  18.             }else if (choice == 3){             //or an int to store the pad type
  19.                 setCustomQuote(getPadChoice(), getAddress());
  20.             }else
  21.                 print();
  22.         }
  23.     }//close main method
  24.  
  25.     public static int menu(){
  26.         int option = 0;
  27.         String menu = ("\n1) Generic Carpet Quote\n2) Custom Carpet Quote <no Pad>"
  28.             + "\n3) Custom Carpet With Pad" +
  29.                 "\n4) Print All Quotes\n5) Exit\n\nChoice:  ");
  30.  
  31.         while(option < 1 || option > 4){
  32.             System.out.print(menu);
  33.             option =  reader.nextInt();
  34.             reader.nextLine();//consume
  35.             if (option == 5)
  36.                 System.exit(99);
  37.         }
  38.         return option;
  39.     }
  40.  
  41.     public static void setGenericQuote(){
  42.         quote[counter] =  new Carpet ();
  43.         counter++;
  44.     }
  45.  
  46.     public static Address getAddress(){
  47.         String name;
  48.         String street;
  49.         String city;
  50.         String stateZip;
  51.  
  52.         System.out.print("\nName:  ");
  53.         name = reader.nextLine();
  54.  
  55.         System.out.print("Street:  ");
  56.         street = reader.nextLine();
  57.  
  58.         System.out.print("City:  ");
  59.         city = reader.nextLine();
  60.  
  61.         System.out.print("State, Zip:  ");
  62.         stateZip = reader.nextLine();
  63.         return new Address(name, street, city, stateZip);
  64.     }
  65.  
  66.     public static int getPadChoice(){
  67.         int padChoice = 0;
  68.         String menu = "\n\t1) Heavy Duty Pad\n\t2) Standard Pad\n\tChoice:  ";
  69.  
  70.         while (padChoice < 1 || padChoice > 2){
  71.             System.out.print(menu);
  72.             padChoice =  reader.nextInt();
  73.             reader.nextLine();
  74.         }
  75.         return padChoice;
  76.     }
  77.  
  78.     public static void setCustomQuote(int pad, Address obj){
  79.  
  80.         int lengthFeet;
  81.         int lengthInches;
  82.         int widthFeet;
  83.         int widthInches;
  84.  
  85.         System.out.print ("\nLength Feet: ");
  86.         lengthFeet = reader.nextInt();
  87.  
  88.         System.out.print ("Length Inches: ");
  89.         lengthInches = reader.nextInt();
  90.  
  91.         System.out.print ("Width Feet:  ");
  92.         widthFeet = reader.nextInt();
  93.  
  94.         System.out.print ("Width Inches:  ");
  95.         widthInches = reader.nextInt();
  96.  
  97.         if (pad == 0) {
  98.  
  99.             quote[counter] = new Carpet(obj, lengthFeet, lengthInches, widthFeet, widthInches);
  100.  
  101.         }
  102.  
  103.         else {
  104.  
  105.             quote[counter] = new Pad(obj, lengthFeet, lengthInches, widthFeet, widthInches, pad);
  106.  
  107.         }
  108.  
  109.         counter++;
  110.     }
  111.  
  112.     public static void print(){
  113.  
  114.         for (int i = 0; i < counter; i++){
  115.             System.out.println(quote[i]);
  116.         }
  117.     }
  118. }//close class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement