I am trying to run this code for class and I cant get the while loop to work properly.
import javax.swing.JOptionPane;
public class Modeling_001C_5WhileLoops {
public static void main(String[] args) {
// Define height and weight and assign values
final int HEIGHT = 70;
final double WEIGHT = 110.4999;
String.format("%10.2f", 12.22);
// Prompt user for height in inches
String applicantsHeightString = JOptionPane.showInputDialog("Enter applicants height in inches" +
" (must exceed 70 to move on)");
double applicantsHeight = Double.parseDouble(applicantsHeightString);
if (applicantsHeight >= HEIGHT) {
JOptionPane.showMessageDialog(null, "Send applicant to get Weighed");
}
else if (applicantsHeight < HEIGHT) {
JOptionPane.showMessageDialog(null, "Send her home...does not qualify");
}
// Prompt user of Weight in pounds
if (applicantsHeight >= HEIGHT) {
String applicantsWeightString = JOptionPane.showInputDialog("Enter Applicants Weight in pounds" +
" (must not exceed 110.4 to qualify)");
double applicantsWeight = Double.parseDouble(applicantsWeightString);
if (applicantsWeight <= WEIGHT) {
JOptionPane.showMessageDialog(null, "Congratulate her and Send to the first Photographer");
}
else if (applicantsWeight > WEIGHT) {
JOptionPane.showMessageDialog(null, "Send her home! Does not meet weight requrements!");
}
// Define variables for Photographer 1
if (applicantsHeight >= HEIGHT && applicantsWeight <= WEIGHT) {
String photographer1String = JOptionPane.showInputDialog("Enter 1st Photographers Score");
double photographer1 = Double.parseDouble(photographer1String);
while (photographer1 >= 10.01) {
JOptionPane.showInputDialog("Invalid score, please enter a score between 1 and 10.00");
}
// here is where I am having the problem. When the user enters a number greater than 10 it should as them to reenter the correct value. However when a new number is entered, it tells them it is invalid and reprompts them. it is an endless loop and will not go down to the if statement.//
if (photographer1 >= 1 && photographer1 <= 10)
JOptionPane.showMessageDialog(null, "Send to 2nd Photographer!");
else if (photographer1 == 0) {
JOptionPane.showMessageDialog(null, "No Pictures! IDon't want to break the camera" +
"...it's my favorite");
}
// Define variables for Photographer 2
if (photographer1 >= 1 && photographer1 <= 10) {
String photographer2String = JOptionPane.showInputDialog("Enter 2nd Photographers Score");
double photographer2 = Double.parseDouble(photographer2String);
if (photographer2 >= 1 && photographer2 <= 10)
JOptionPane.showMessageDialog(null, "Send to 3rd Photographer!");
else if (photographer2 == 0) {
JOptionPane.showMessageDialog(null, "What was the last guy thinking?" +
" Send her home! NOW!!");
}
// Define variables for Photographer 3
if (photographer2 >= 1 && photographer2 <= 10) {
String photographer3String = JOptionPane.showInputDialog("Enter 3rd Photographers Score");
double photographer3 = Double.parseDouble(photographer3String);
if (photographer3 >= 1 && photographer3 <= 10)
JOptionPane.showMessageDialog(null, "Calculate Average Score");
else if (photographer3 == 0) {
JOptionPane.showMessageDialog(null, "Waste of my time. How did she make it this far?");
}
// Define average and assign a value
double averageScore = (photographer1 + photographer2 + photographer3) / 3;
String.format("%10.2f", 12.22);
if (averageScore <= 7.9 && photographer3 != 0) {
JOptionPane.showMessageDialog(null, "Send Her Home!");
}
else if (averageScore >= 8 && averageScore <=8.7) {
JOptionPane.showMessageDialog(null, "Average " + averageScore + "!" +
"Too high risk, not worth spending your money!!");
}
else if (averageScore >= 8.8 && averageScore <= 9.3) {
JOptionPane.showMessageDialog(null, " Average " + averageScore + "!" +
" Low to Medium risk....has a pretty good chance to make you money!");
}
else if (averageScore >= 9.4 && averageScore <= 9.9) {
JOptionPane.showMessageDialog(null, " Average " + averageScore + "!" +
" Low risk to good investment....Excelant chance you will make money " +
"bring her on board!");
}
else if (averageScore == 10) {
JOptionPane.showMessageDialog(null, " Average " + averageScore + "!" +
" Get her to sign a contract before she realizes how much she could take you for!!!");
}
}
}
}
}
}
}
Any help is greatly appreciated. I am only in my third week of my first class, so I don't know much.
Kat