Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2016
    Posts
    10
    Rep Power
    0

    Default Can I put this into any loop?

    Hi everyone I am new to Java and I would just like to know if I can make this long program into a loop to save time.

    Thanks here is my program -

    import java.util.Scanner;

    public class FloorsProgram {

    public static void main(String[] args){
    Scanner keyboardInput = new Scanner(System.in);
    Scanner keyboardInput2 = new Scanner(System.in);
    Scanner keyboardInput3 = new Scanner(System.in);
    Scanner keyboardInput4 = new Scanner(System.in);
    Scanner keyboardInput5 = new Scanner(System.in);
    Scanner keyboardInput6 = new Scanner(System.in);
    Scanner keyboardInput7 = new Scanner(System.in);
    Scanner keyboardInput8 = new Scanner(System.in);
    Scanner keyboardInput9 = new Scanner(System.in);
    Scanner keyboardInput10 = new Scanner(System.in);
    Scanner keyboardInput11 = new Scanner(System.in);
    Scanner keyboardInput12 = new Scanner(System.in);

    String r1 = "";
    String r2 = "";
    String r3 = "";
    String r4 = "";
    String r5 = "";
    String r6 = "";
    String r7 = "";
    String r8 = "";
    String r9 = "";
    String r10 = "";
    String r11 = "";
    String r12 = "";
    String r13 = "";
    String r14 = "";
    String r15 = "";
    String r16 = "";
    String r17 = "";
    String r18 = "";
    String r19 = "";
    String r20 = "";
    String E = "";
    String IL = "Input the length for ";
    String IW = "Input the width for ";
    String yesOrNo = "";

    double length1 = 0, width1 = 0;
    double length2 = 0, width2 = 0;
    double length3 = 0, width3 = 0;
    double length4 = 0, width4 = 0;
    double length5 = 0, width5 = 0;
    double length6 = 0, width6 = 0;
    double length7 = 0, width7 = 0;
    double length8 = 0, width8 = 0;
    double length9 = 0, width9 = 0;
    double length10 = 0, width10 = 0;
    double length11 = 0, width11 = 0;
    double length12 = 0, width12 = 0;
    double length13 = 0, width13 = 0;
    double length14 = 0, width14 = 0;
    double length15 = 0, width15 = 0;
    double length16 = 0, width16 = 0;
    double length17 = 0, width17 = 0;
    double length18 = 0, width18 = 0;
    double length19 = 0, width19 = 0;
    double length20 = 0, width20 = 0;

    double wasteFactor = 0;
    double newArea;
    double squareFeetPerBox = 0;


    System.out.println("Welcome to the FloorsProgram! ©FloorsProgram 2016");
    System.out.println("Press enter to start");
    E = keyboardInput.nextLine();

    System.out.println("Enter the name of you're first room");
    r1 = keyboardInput.nextLine();

    System.out.println("Input the length for " + r1);
    length1 = keyboardInput.nextDouble();

    System.out.println("Input the width for " +r1);
    width1 = keyboardInput.nextDouble();

    double area = length1 * width1;

    System.out.println("The total area for " + r1 + " is: " + area + " sq ft");

    System.out.println("Do you have another room? Input Yes or No");

    yesOrNo = keyboardInput2.nextLine();

    if(yesOrNo.equals("Yes")){
    System.out.println("What is the name of you're second room?");
    }

    else if(yesOrNo.equals("yes"))
    System.out.println("What is the name of you're second room?");

    else if(yesOrNo.equals("y"))
    System.out.println("What is the name of you're second room?");

    else if(yesOrNo.equals("Y"))
    System.out.println("What is the name of you're second room?");

    else if(yesOrNo.equals("no")){
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * area;


    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    else{
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * area;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");

    }

    r2 = keyboardInput2.nextLine();

    System.out.println("Input the length for " + r2);
    length2 = keyboardInput.nextDouble();

    System.out.println("Input the width for " + r2);
    width2 = keyboardInput.nextDouble();

    double area2 = length2 * width2;

    System.out.println("The total area of " + r2 + " is " + area2 + " sq ft");

    E = keyboardInput.nextLine();

    double Area = area + area2;

    System.out.println("The total area of " + r1 + " and " + r2 + " is " + Area + " sq ft");

    E = keyboardInput.nextLine();

    System.out.println("Do you have another room? Input Yes or No");

    yesOrNo = keyboardInput2.nextLine();

    if(yesOrNo.equals("Yes"))
    System.out.println("What is the name of you're third room?");

    else if(yesOrNo.equals("yes"))
    System.out.println("What is the name of you're third room?");

    else if(yesOrNo.equals("y"))
    System.out.println("What is the name of you're third room?");

    else if(yesOrNo.equals("Y"))
    System.out.println("What is the name of you're third room?");

    else if(yesOrNo.equals("no")){
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");

    }
    else{
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");

    }

    r3 = keyboardInput2.nextLine();

    System.out.println(IL + r3);
    length3 = keyboardInput3.nextDouble();

    System.out.println(IW + r3);
    width3 = keyboardInput3.nextDouble();

    double area3 = length3 * width3;

    System.out.println("The total area for " + r3 + " is " + area3 + " sq ft");

    E = keyboardInput.nextLine();

    double Area2 = area + area2 + area3;

    System.out.println("The total area for " + r1 + ", " + r2 + ", and " + r3 + " is " + Area2 + " sq ft ");

    E = keyboardInput.nextLine();

    System.out.println("Do you have another room? Input Yes or No");

    yesOrNo = keyboardInput2.nextLine();

    if(yesOrNo.equals("Yes"))
    System.out.println("What is the name of you're fourth room?");

    else if(yesOrNo.equals("yes"))
    System.out.println("What is the name of you're fourth room?");

    else if(yesOrNo.equals("y"))
    System.out.println("What is the name of you're fourth room?");

    else if(yesOrNo.equals("Y"))
    System.out.println("What is the name of you're fourth room?");

    else if(yesOrNo.equals("No")){
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area2;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");

    }

    else
    {
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area2;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");

    }

    r4 = keyboardInput4.nextLine();

    System.out.println("Input the length of " + r4);
    length4 = keyboardInput.nextDouble();

    System.out.println("Input the width of " + r4);
    width4 = keyboardInput.nextDouble();

    double area4 = length4 * width4;
    double Area3 = area + area2 + area3 + area4;

    System.out.println("The total area of " + r4 + " is " + area4 + " sq ft");

    E = keyboardInput.nextLine();

    System.out.println("The total area of all 4 room's is " + Area3 + " sq ft");

    System.out.println("Do you have another room? Input Yes or No");

    yesOrNo = keyboardInput2.nextLine();

    if(yesOrNo.equals("Yes")){
    System.out.println("What is the name of you're fifth room?");
    }

    else if(yesOrNo.equals("yes"))
    System.out.println("What is the name of you're fifth room?");

    else if(yesOrNo.equals("y"))
    System.out.println("What is the name of you're fifth room?");

    else if(yesOrNo.equals("Y"))
    System.out.println("What is the name of you're fifth room?");

    else if(yesOrNo.equals("no")){
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area3;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    else{
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area3;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    r5 = keyboardInput.nextLine();

    System.out.println("Input the length for " + r5);
    length5 = keyboardInput.nextDouble();

    System.out.println("Input the width for "+ r5);
    width5 = keyboardInput.nextDouble();

    double area5 = length5 * width5;

    System.out.println("The total area for " + r5 + " is " + area5);

    E = keyboardInput.nextLine();

    double Area4 = area + area2 + area3 + area4 + area5;

    System.out.println("The total area for all five rooms is " + Area4 + " sq ft");

    E = keyboardInput.nextLine();

    System.out.println("Do you have another room? Input Yes or No");

    yesOrNo = keyboardInput2.nextLine();

    if(yesOrNo.equals("Yes")){
    System.out.println("What is the name of you're sixth room?");
    }

    else if(yesOrNo.equals("yes"))
    System.out.println("What is the name of you're sixth room?");

    else if(yesOrNo.equals("y"))
    System.out.println("What is the name of you're sixth room?");

    else if(yesOrNo.equals("Y"))
    System.out.println("What is the name of you're sixth room?");

    else if(yesOrNo.equals("no")){
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area4;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    else{
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area4;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    r6 = keyboardInput6.nextLine();

    System.out.println("Input the length for " + r6);
    length6 = keyboardInput.nextDouble();

    System.out.println("Input the width for "+ r6);
    width6 = keyboardInput.nextDouble();


    double area6 = length6 * width6;

    System.out.println("The total area for " + r6 + " is " + area6);

    E = keyboardInput.nextLine();

    double Area5 = area + area2 + area3 + area4 + area5 + area6;

    System.out.println("The total area for all six rooms is " + Area5 + " sq ft");

    E = keyboardInput.nextLine();

    System.out.println("Do you have another room? Input Yes or No");

    yesOrNo = keyboardInput2.nextLine();

    if(yesOrNo.equals("Yes")){
    System.out.println("What is the name of you're seventh room?");
    }

    else if(yesOrNo.equals("yes"))
    System.out.println("What is the name of you're seventh room?");

    else if(yesOrNo.equals("y"))
    System.out.println("What is the name of you're seventh room?");

    else if(yesOrNo.equals("Y"))
    System.out.println("What is the name of you're seventh room?");

    else if(yesOrNo.equals("no")){
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area5;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    else{
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area5;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    r7 = keyboardInput6.nextLine();

    System.out.println("Input the length for " + r7);
    length7 = keyboardInput.nextDouble();

    System.out.println("Input the width for "+ r7);
    width7 = keyboardInput.nextDouble();


    double area7 = length7 * width7;

    System.out.println("The total area for " + r7 + " is " + area7);

    E = keyboardInput.nextLine();

    double Area6 = area + area2 + area3 + area4 + area5 + area6 + area7;

    System.out.println("The total area for all seven rooms is " + Area6 + " sq ft");

    E = keyboardInput.nextLine();

    System.out.println("Do you have another room? Input Yes or No");

    yesOrNo = keyboardInput5.nextLine();

    if(yesOrNo.equals("Yes")){
    System.out.println("What is the name of you're eigth room?");
    }

    else if(yesOrNo.equals("yes"))
    System.out.println("What is the name of you're eigth room?");

    else if(yesOrNo.equals("y"))
    System.out.println("What is the name of you're eigth room?");

    else if(yesOrNo.equals("Y"))
    System.out.println("What is the name of you're eigth room?");

    else if(yesOrNo.equals("no")){
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area6;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    else{
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area6;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    r8 = keyboardInput6.nextLine();

    System.out.println("Input the length for " + r8);
    length8 = keyboardInput.nextDouble();

    System.out.println("Input the width for "+ r8);
    width8 = keyboardInput.nextDouble();


    double area8 = length8 * width8;

    System.out.println("The total area for " + r8 + " is " + area8);

    E = keyboardInput.nextLine();

    double Area7 = area + area2 + area3 + area4 + area5 + area6 + area7 + area8;

    System.out.println("The total area for all eight rooms is " + Area7 + " sq ft");

    E = keyboardInput.nextLine();

    System.out.println("Do you have another room? Input Yes or No");

    yesOrNo = keyboardInput5.nextLine();

    if(yesOrNo.equals("Yes")){
    System.out.println("What is the name of you're ninth room?");
    }

    else if(yesOrNo.equals("yes"))
    System.out.println("What is the name of you're ninth room?");

    else if(yesOrNo.equals("y"))
    System.out.println("What is the name of you're ninth room?");

    else if(yesOrNo.equals("Y"))
    System.out.println("What is the name of you're ninth room?");

    else if(yesOrNo.equals("no")){
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area7;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    else{
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area7;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    r9 = keyboardInput7.nextLine();

    System.out.println("Input the length for " + r9);
    length9 = keyboardInput.nextDouble();

    System.out.println("Input the width for "+ r9);
    width9 = keyboardInput.nextDouble();


    double area9 = length9 * width9;

    System.out.println("The total area for " + r9 + " is " + area9);

    E = keyboardInput.nextLine();

    double Area8 = area + area2 + area3 + area4 + area5 + area6 + area7 + area8 + area9;

    E = keyboardInput.nextLine();

    System.out.println("The total area for all nine rooms is " + Area8 + " sq ft");

    System.out.println("Do you have another room? Input Yes or No");

    yesOrNo = keyboardInput6.nextLine();

    if(yesOrNo.equals("Yes")){
    System.out.println("What is the name of you're tenth room?");
    }

    else if(yesOrNo.equals("yes"))
    System.out.println("What is the name of you're tenth room?");

    else if(yesOrNo.equals("y"))
    System.out.println("What is the name of you're tenth room?");

    else if(yesOrNo.equals("Y"))
    System.out.println("What is the name of you're tenth room?");

    else if(yesOrNo.equals("no")){
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area8;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    else{
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area8;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    r10 = keyboardInput7.nextLine();

    System.out.println("Input the length for " + r10);
    length10 = keyboardInput.nextDouble();

    System.out.println("Input the width for "+ r10);
    width10 = keyboardInput.nextDouble();


    double area10 = length10 * width10;

    System.out.println("The total area for " + r10 + " is " + area10);

    E = keyboardInput.nextLine();

    double Area9 = area + area2 + area3 + area4 + area5 + area6 + area7 + area8 + area9 + area10;

    System.out.println("The total area for all ten rooms is " + Area9 + " sq ft");


    E = keyboardInput.nextLine();
    System.out.println("Do you have another room? Input Yes or No");

    yesOrNo = keyboardInput6.nextLine();

    if(yesOrNo.equals("Yes")){
    System.out.println("What is the name of you're eleventh room?");
    }

    else if(yesOrNo.equals("yes"))
    System.out.println("What is the name of you're eleventh room?");

    else if(yesOrNo.equals("y"))
    System.out.println("What is the name of you're eleventh room?");

    else if(yesOrNo.equals("Y"))
    System.out.println("What is the name of you're eleventh room?");

    else if(yesOrNo.equals("no")){
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area9;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    else{
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area9;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    r11 = keyboardInput7.nextLine();

    System.out.println("Input the length for " + r11);
    length11 = keyboardInput.nextDouble();

    System.out.println("Input the width for "+ r11);
    width11 = keyboardInput.nextDouble();


    double area11 = length11 * width11;

    System.out.println("The total area for " + r11 + " is " + area11);

    E = keyboardInput.nextLine();

    double Area10 = area + area2 + area3 + area4 + area5 + area6 + area7 + area8 + area9 + area10 + area11;

    System.out.println("The total area for all eleven rooms is " + Area10 + " sq ft");


    E = keyboardInput.nextLine();
    System.out.println("Do you have another room? Input Yes or No");

    yesOrNo = keyboardInput6.nextLine();

    if(yesOrNo.equals("Yes")){
    System.out.println("What is the name of you're twelfth room?");
    }

    else if(yesOrNo.equals("yes"))
    System.out.println("What is the name of you're twelfth room?");

    else if(yesOrNo.equals("y"))
    System.out.println("What is the name of you're twelfth room?");

    else if(yesOrNo.equals("Y"))
    System.out.println("What is the name of you're twelfth room?");

    else if(yesOrNo.equals("no")){
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area10;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    else{
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area10;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    r12 = keyboardInput8.nextLine();

    System.out.println("Input the length for " + r12);
    length12 = keyboardInput.nextDouble();

    System.out.println("Input the width for "+ r12);
    width12 = keyboardInput.nextDouble();


    double area12 = length12 * width12;

    System.out.println("The total area for " + r12 + " is " + area12);

    E = keyboardInput.nextLine();

    double Area11 = area + area2 + area3 + area4 + area5 + area6 + area7 + area8 + area9 + area10 + area11 + area12;

    System.out.println("The total area for all twelve rooms is " + Area11 + " sq ft");


    E = keyboardInput.nextLine();
    System.out.println("Do you have another room? Input Yes or No");

    yesOrNo = keyboardInput6.nextLine();

    if(yesOrNo.equals("Yes")){
    System.out.println("What is the name of you're thirteenth room?");
    }

    else if(yesOrNo.equals("yes"))
    System.out.println("What is the name of you're thirteenth room?");

    else if(yesOrNo.equals("y"))
    System.out.println("What is the name of you're thirteenth room?");

    else if(yesOrNo.equals("Y"))
    System.out.println("What is the name of you're thirteenth room?");

    else if(yesOrNo.equals("no")){
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area11;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    else{
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area11;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    r13 = keyboardInput8.nextLine();

    System.out.println("Input the length for " + r13);
    length13 = keyboardInput.nextDouble();

    System.out.println("Input the width for "+ r13);
    width13 = keyboardInput.nextDouble();


    double area13 = length13 * width13;

    System.out.println("The total area for " + r13 + " is " + area13);

    E = keyboardInput.nextLine();

    double Area12 = area + area2 + area3 + area4 + area5 + area6 + area7 + area8 + area9 + area10 + area11 + area12 + area13;

    System.out.println("The total area for all thirteen rooms is " + Area12 + " sq ft");


    E = keyboardInput.nextLine();
    System.out.println("Do you have another room? Input Yes or No");

    yesOrNo = keyboardInput7.nextLine();

    if(yesOrNo.equals("Yes")){
    System.out.println("What is the name of you're fourteenth room?");
    }

    else if(yesOrNo.equals("yes"))
    System.out.println("What is the name of you're fourteenth room?");

    else if(yesOrNo.equals("y"))
    System.out.println("What is the name of you're fourteenth room?");

    else if(yesOrNo.equals("Y"))
    System.out.println("What is the name of you're fourteenth room?");

    else if(yesOrNo.equals("no")){
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area12;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    else{
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area12;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    r14 = keyboardInput9.nextLine();

    System.out.println("Input the length for " + r14);
    length14 = keyboardInput.nextDouble();

    System.out.println("Input the width for "+ r14);
    width14 = keyboardInput.nextDouble();


    double area14 = length14 * width14;

    System.out.println("The total area for " + r14 + " is " + area14);

    E = keyboardInput.nextLine();

    double Area13 = area + area2 + area3 + area4 + area5 + area6 + area7 + area8 + area9 + area10 + area11 + area12 + area13 + area14;

    System.out.println("The total area for all fourteen rooms is " + Area13 + " sq ft");


    E = keyboardInput.nextLine();

    System.out.println("Do you have another room? Input Yes or No");

    yesOrNo = keyboardInput8.nextLine();

    if(yesOrNo.equals("Yes")){
    System.out.println("What is the name of you're fifteenth room?");
    }

    else if(yesOrNo.equals("yes"))
    System.out.println("What is the name of you're fifteenth room?");

    else if(yesOrNo.equals("y"))
    System.out.println("What is the name of you're fifteenth room?");

    else if(yesOrNo.equals("Y"))
    System.out.println("What is the name of you're fifteenth room?");

    else if(yesOrNo.equals("no")){
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area13;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    else{
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area13;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    r15 = keyboardInput8.nextLine();

    System.out.println("Input the length for " + r15);
    length15 = keyboardInput.nextDouble();

    System.out.println("Input the width for "+ r15);
    width15 = keyboardInput.nextDouble();


    double area15 = length15 * width15;

    System.out.println("The total area for " + r12 + " is " + area12);

    E = keyboardInput.nextLine();

    double Area14 = area + area2 + area3 + area4 + area5 + area6 + area7 + area8 + area9 + area10 + area11 + area12
    + area13 + area14 + area15;

    System.out.println("The total area for all 15 rooms is " + Area14 + " sq ft");

    E = keyboardInput.nextLine();
    System.out.println("Do you have another room? Input Yes or No");

    yesOrNo = keyboardInput8.nextLine();

    if(yesOrNo.equals("Yes")){
    System.out.println("What is the name of you're sixteenth room?");
    }

    else if(yesOrNo.equals("yes"))
    System.out.println("What is the name of you're sixteenth room?");

    else if(yesOrNo.equals("y"))
    System.out.println("What is the name of you're sixteenth room?");

    else if(yesOrNo.equals("Y"))
    System.out.println("What is the name of you're sixteenth room?");

    else if(yesOrNo.equals("no")){
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area14;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }

    else{
    System.out.println("Input the waste factor");
    wasteFactor = keyboardInput3.nextDouble();

    double TWF = (wasteFactor / 100 + 1) * Area14;

    double TWFR = Math.round(TWF);

    System.out.println("The total square footage (waste factor included) is " + TWFR);

    double sqFTPerBox = 0;

    System.out.println("Input the SQFT per box");
    sqFTPerBox = keyboardInput3.nextDouble();

    double SQFTPerBox = TWF / sqFTPerBox;

    double finalSQFTPerBox = Math.ceil(SQFTPerBox);

    System.out.println("You need " + finalSQFTPerBox + " boxes");
    }


    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Can I put this into any loop?

    It looks like using arrays would shorten the code.

    make this long program into a loop to save time.
    What in the program is taking too much time?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Can I put this into any loop?

    A few observations:

    1. You have all of that in main. Write some methods and utility classes to help reduce the code.
    2. Use variables for common repeated strings (less typing involved).
    3. You can use one instance of Scanner class for everything. No need for all of those instances.
    4. Always use {}, even for one line if statements and similar constructs. It will save you debugging time in the long run.
    5. Consolidate code as follows:

    Don't do this:

    Java Code:
          yesOrNo = keyboardInput2.nextLine();
    
          if (yesOrNo.equals("Yes"))
             System.out.println("What is the name of you're third room?");
    
          else if (yesOrNo.equals("yes"))
             System.out.println("What is the name of you're third room?");
    
          else if (yesOrNo.equals("y"))
             System.out.println("What is the name of you're third room?");
    
          else if (yesOrNo.equals("Y"))
             System.out.println("What is the name of you're third room?");
    Do something like this:
    Java Code:
          yesOrNo = keyboardInput2.nextLine().toLowerCase().trim();
          if (yesOrNo.charAt(0) == 'y') {
                 System.out.println("What is the name of you're third room?");
          }
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    Join Date
    Oct 2016
    Posts
    10
    Rep Power
    0

    Default Re: Can I put this into any loop?

    Ok thanks everybody for your help!

  5. #5
    Join Date
    Oct 2016
    Posts
    10
    Rep Power
    0

    Default Re: Can I put this into any loop?

    Thanks Jim, but is there any way to make this program into a loop?

  6. #6
    Join Date
    Oct 2016
    Posts
    10
    Rep Power
    0

    Default Re: Can I put this into any loop?

    Well it's not that it takes a really long time to write the code. Its just that the whole point of the program is to help floors sales person save time by doing the math for square feet and how many boxes of material to order, how much extra material to order, etc.. I only have 20 rooms in this program what if somebody has more than 20 rooms it gets tiring by adding another room one at a time, so that's why I'm asking if its possible to make this program into a loop instead of adding another room one at a time.

  7. #7
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    399
    Rep Power
    6

    Default Re: Can I put this into any loop?

    From what I saw the Math is all the same, so I would create a Room class with the properties length, width, name and whatever you calculate. Create a new instance of Room for each room and set the properties. Add the rooms into a collection (in Room constructor should work here). If you want the total or a list of all rooms you just loop over the Collection. I'd say 25-35 lines of code with this solution. No restrictions in terms of number of rooms. .. and it comes closer to the idea of OOP.

  8. #8
    Join Date
    Oct 2016
    Posts
    10
    Rep Power
    0

Similar Threads

  1. Simple loop within a loop not working.
    By supremegrandruler in forum New To Java
    Replies: 3
    Last Post: 03-21-2014, 09:27 AM
  2. Converting a while loop to a for loop
    By danboy4 in forum New To Java
    Replies: 7
    Last Post: 08-08-2012, 03:35 PM
  3. Replies: 2
    Last Post: 11-07-2011, 02:25 AM
  4. Replies: 1
    Last Post: 10-01-2011, 02:12 AM
  5. JTextField loop 2x for-loop WEIRD!
    By Streetproject in forum AWT / Swing
    Replies: 2
    Last Post: 02-16-2011, 05:46 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •