Here is the code I am working with.
The first problem I am having is that when I run it, the loop in the method "che_amo" doesn't work properly. It is supposed to keep asking for a cheque number and the cheque amount, until the user enters a -1 for a cheque number, then it is supposed to move on. But what happens is once the user enters in a -1 for a cheque number, it asks them again for a cheque number, and they must enter another -1 in order for it to move on.
If I take out "sub_total = che_amo();" in the method "gst", then the problem is solved. What is the reason for this?
My second problem is very similar to the first, except that the line "gst_amo = sub_total * gst;" in the method "gst" is returning the value of sub_total * gst, but it isn't taking the actual sub total, it is just taking the value that I declared the subtotal to be in the method "che_amo".
Could someone please help me figure this out? I would be greatly appreciative.
Thank you,
Nick Young.
Quote:
public class SimpleMethods
{
/**
* replace this comment with your own
*
*/
public static void main()
{
balance();
header();
che_amo();
gst();
}
//End of Main
//////////////////////////////////////////////////////////
//Start of Methods
public static double balance()
{
double balance; //The starting balance of users account.
final double ovr_dft = 50.00; //Overdraft on users account. In this program, it is always 50 dollars!
balance = IO.readDouble("Please Enter Your Current Account Balance: ");
System.out.println("Your Current Account Balance is: " + balance);
System.out.println("You have an overdraft protection of " + ovr_dft);
System.out.println();
return balance;
}
public static void header()
{
System.out.print("Cheque No.");
System.out.print(" ");
System.out.print("Amount");
System.out.println();
}
public static double che_amo()
{
double cheque,
amount,
sub_total = 0.0;
cheque = IO.readDouble("Please Enter Cheque Number: ");
while (cheque > 0)
{
System.out.print(" " + cheque);
amount = IO.readDouble("Please Enter Cheque Amount: ");
System.out.print(" " + amount);
sub_total = sub_total + cheque;
cheque = IO.readDouble("Please Enter Cheque Number: ");
System.out.println();
}
return sub_total;
}
public static void gst()
{
double sub_total,
gst = 0.07,
gst_amo,
total;
sub_total = che_amo();
gst_amo = sub_total * gst;
System.out.println("The total GST is: " + gst_amo);
total = sub_total + gst;
System.out.println("You Owe a Total of: " + total);
}
}
|