Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CarpetDriverMiller{
- static Scanner reader = new Scanner (System.in);
- static Carpet[] quote = new Carpet[20];
- static int counter = 0;
- public static void main (String args []){
- int choice;
- while(true){
- choice = menu();
- if(choice == 1){
- setGenericQuote();
- }else if(choice == 2){
- setCustomQuote(0, getAddress()); //you may use either a String
- }else if (choice == 3){ //or an int to store the pad type
- setCustomQuote(getPadChoice(), getAddress());
- }else
- print();
- }
- }//close main method
- public static int menu(){
- int option = 0;
- String menu = ("\n1) Generic Carpet Quote\n2) Custom Carpet Quote <no Pad>"
- + "\n3) Custom Carpet With Pad" +
- "\n4) Print All Quotes\n5) Exit\n\nChoice: ");
- while(option < 1 || option > 4){
- System.out.print(menu);
- option = reader.nextInt();
- reader.nextLine();//consume
- if (option == 5)
- System.exit(99);
- }
- return option;
- }
- public static void setGenericQuote(){
- quote[counter] = new Carpet ();
- counter++;
- }
- public static Address getAddress(){
- String name;
- String street;
- String city;
- String stateZip;
- System.out.print("\nName: ");
- name = reader.nextLine();
- System.out.print("Street: ");
- street = reader.nextLine();
- System.out.print("City: ");
- city = reader.nextLine();
- System.out.print("State, Zip: ");
- stateZip = reader.nextLine();
- return new Address(name, street, city, stateZip);
- }
- public static int getPadChoice(){
- int padChoice = 0;
- String menu = "\n\t1) Heavy Duty Pad\n\t2) Standard Pad\n\tChoice: ";
- while (padChoice < 1 || padChoice > 2){
- System.out.print(menu);
- padChoice = reader.nextInt();
- reader.nextLine();
- }
- return padChoice;
- }
- public static void setCustomQuote(int pad, Address obj){
- int lengthFeet;
- int lengthInches;
- int widthFeet;
- int widthInches;
- System.out.print ("\nLength Feet: ");
- lengthFeet = reader.nextInt();
- System.out.print ("Length Inches: ");
- lengthInches = reader.nextInt();
- System.out.print ("Width Feet: ");
- widthFeet = reader.nextInt();
- System.out.print ("Width Inches: ");
- widthInches = reader.nextInt();
- if (pad == 0) {
- quote[counter] = new Carpet(obj, lengthFeet, lengthInches, widthFeet, widthInches);
- }
- else {
- quote[counter] = new Pad(obj, lengthFeet, lengthInches, widthFeet, widthInches, pad);
- }
- counter++;
- }
- public static void print(){
- for (int i = 0; i < counter; i++){
- System.out.println(quote[i]);
- }
- }
- }//close class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement