Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (anonymous):

Please tell me why I get a "moreCalls cannot be resolved to a variable" error at the while statement.

OpenStudy (anonymous):

import javax.swing.JOptionPane; public class TelephoneBill { public static void main(String[] args) { do { String cpm = JOptionPane.showInputDialog("What is the cost per minute of your telephone call? "); double costPerMinute = Double.parseDouble(cpm); String callType = JOptionPane.showInputDialog("What type of call? (local or long distance?") ; String callTime = JOptionPane.showInputDialog("How many minutes was your call?"); double callLength = Double.parseDouble(callTime); double priceOfCall; if (callType == "local"){ priceOfCall = processLocal(callLength, costPerMinute);} else if (callType == "long distance"){ priceOfCall = processLongDistance(costPerMinute);} double totalCost = priceOfCall; String moreCalls = JOptionPane.showInputDialog("Do you want to continue? ( enter: yes or no)");} while (moreCalls == "yes") ; } public static double processLocal(double length, double price) { double cost = ( length * price); if (cost>2) { cost = 2;} System.out.println("The cost of this local call is: $" + cost); return cost; } public static double processLongDistance (double length){ double cost; if (length > 20 ){ cost = (length-20) * .05 + 1;} else cost = 5; System.out.println("The cost of this longdistance call is: $" + cost); return cost;} }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!