D
DBJohnston0104
I'm trying to complete a homework assignment where a window asks for a
billType (ex: Rent, Food, Gas, etc.) and then the next window asks for
an amount. It should keep a running total of all bills entered and
continue to loop until you enter the word "done" as a billType. I
just don't understand why the code below doesn't work. Now I don't
want anyone to give me the answer or the correct code, but I would
like some hints. I'm really interested in getting this to work so
here I am. And here is what I have so far:
// MonthlyBills.java - This program calculates the total of your
monthly bills.
// Input: Bill type and bill amount.
// Output: Prints the total of your monthly bills.
import javax.swing.JOptionPane;
public class MonthlyBills
{
public static void main(String args[])
{
String billType; // Description of bill.
String stringAmount; // String version of bill amount.
double billAmount; // Amount of the bill.
double sum = 0; // Accumulates sum of bills.
/* You should set up your loop to execute as long as the user
has not entered the word done. You can use these input and
output statements anywhere in your program. They are not in
any particular order.
*/
do
{
// This input statement asks the user to enter a bill type or the
word none.
billType = JOptionPane.showInputDialog("Enter bill type or the word
done to quit.");
if(billType != "done")
{
// This input statement asks your user to enter a bill amount.
stringAmount = JOptionPane.showInputDialog("Enter amount of
bill");
// This statement converts the string version of the amount to a
double.
billAmount = Double.parseDouble(stringAmount);
//This totals up the amount of the bills
sum += billAmount;
}
}while(billType != "done");
// This statement displays the sum of monthly bills.
System.out.println("Sum of monthly bills is $: " + sum);
// This statement causes the program to exit.
System.exit(0);
} // End of main() method.
} // End of MonthlyBills class.
billType (ex: Rent, Food, Gas, etc.) and then the next window asks for
an amount. It should keep a running total of all bills entered and
continue to loop until you enter the word "done" as a billType. I
just don't understand why the code below doesn't work. Now I don't
want anyone to give me the answer or the correct code, but I would
like some hints. I'm really interested in getting this to work so
here I am. And here is what I have so far:
// MonthlyBills.java - This program calculates the total of your
monthly bills.
// Input: Bill type and bill amount.
// Output: Prints the total of your monthly bills.
import javax.swing.JOptionPane;
public class MonthlyBills
{
public static void main(String args[])
{
String billType; // Description of bill.
String stringAmount; // String version of bill amount.
double billAmount; // Amount of the bill.
double sum = 0; // Accumulates sum of bills.
/* You should set up your loop to execute as long as the user
has not entered the word done. You can use these input and
output statements anywhere in your program. They are not in
any particular order.
*/
do
{
// This input statement asks the user to enter a bill type or the
word none.
billType = JOptionPane.showInputDialog("Enter bill type or the word
done to quit.");
if(billType != "done")
{
// This input statement asks your user to enter a bill amount.
stringAmount = JOptionPane.showInputDialog("Enter amount of
bill");
// This statement converts the string version of the amount to a
double.
billAmount = Double.parseDouble(stringAmount);
//This totals up the amount of the bills
sum += billAmount;
}
}while(billType != "done");
// This statement displays the sum of monthly bills.
System.out.println("Sum of monthly bills is $: " + sum);
// This statement causes the program to exit.
System.exit(0);
} // End of main() method.
} // End of MonthlyBills class.