I need to ask if the user wants to add another product receive a yes or no and run the loop again? Also I need to count the products and add the prices together to figure an average?
private double computeAverageSales() { WebHost webHost; double average = 0; int counter = 0; double total = 0; boolean again = true; double webHostPrice = 0; System.out.println("Enter 0 to end"); System.out.println("Please enter the price of the new package: $"); webHostPrice = scanner.nextDouble(); while (true){ for (int i = 0; i <= 0; i++) { if (webHostPrice == 0) { break; } else if (webHostPrice <= -1) { System.out.println("Please enter a positive number!"); } else if (webHostPrice >= 500) { System.out.println("Are you sure that seems a little high!"); } else if (webHostPrice == 0){ break; } System.out.println("Please enter the product ID "); int webHostId = scanner.nextInt(); if (webHostId <= -1) { System.out.println("Please enter a positive number!"); } else if (webHostId > 10000) { System.out.println("Sorry please enter a valid ID number"); } else if (webHostId == 0) { break; } System.out.println("What is the product name: "); String webHostName = scanner.next(); if (webHostName == null) { System.out.println("Please enter a valid Product Name!"); } if (webHostName.equals("end")) { break; } System.out.println("Please enter the required Bandwidth needed for your site? "); double webHostBandwidth = scanner.nextDouble(); if (webHostBandwidth <= -1) { System.out.println("Please enter a positive number!"); webHostBandwidth = scanner.nextDouble(); ///LOOK Here's another INFINITE LOOP... This while will never quit } else if (webHostBandwidth > 10000000) { System.out.println("Please enter a vaild number!"); } else if (webHostBandwidth == 0) { break; } System.out.println("How many FTP accounts do you need? "); int webHostFtp = scanner.nextInt(); if (webHostFtp <= -1) { System.out.println("Please enter a positive number!"); ///LOOK And, another INFINITE LOOP !! } else if (webHostFtp > 120) { System.out.println("Please enter a valid number!"); } else if (webHostFtp == 0) { break; } System.out.print("How many email accounts do you need? "); int webHostMail = scanner.nextInt(); if (webHostMail <= -1) { System.out.println("Please enter a positive number!"); ///LOOK And still another INFINITE LOOP !! } else if (webHostMail > 225) { System.out.println("Please enter a valid number!"); } else if (webHostMail == 0) { break; } System.out.print("What is your domain name? "); String webHostDomain = scanner.next(); webHostDomain = webHostDomain.trim(); if (webHostDomain.length() < 0) { System.out.println("Please enter a valid domain name!"); webHostDomain = webHostDomain.trim(); } else if (webHostDomain.equals("0")) { break; } System.out.println("Would you like to add another product? "); } // end for statement average = total / (counter - 1); return average; } // end while statement }
I know the code is messing but that is because I have worked 4 days on this I am a newbie any suggestions is much appreciated!