Ok i have gotten stuck on this program and I need help

This program is supposed to calculate the balance of a
checking account after the user has entered
the type of action (withdrawl, deposit)
they would like to do.

My output should be a report that prints the beginning balance, the action (deposit or withdrawl), the amount and the ending balance.

Thank You Guys In Advance.

public class CheckingAcct
{
   public static void main (String [] args)

   {
     double balance;
     double amount;
     char accttype;





     System.out.print("Enter checking account balance:  ");
     balance = Input.readDouble ();
     balance=0;
     System.out.print("Enter account type D=Deposit, W=Withdrawl or    B=Balance to end");
     accttype = Input.readChar ();

     if (accttype.equalsIgnoreCase("d"))
     {
        System.out.print("Enter deposit amount: ");
        amount = Input.readDouble ();
        balance = balance + amount;
     }
     else if (accttype.equalsIgnoreCase("w"))
     {
        System.out.print("Enter withdrawl amount: ");
        amount = Input.readDouble ();
        balance = balance + amount;
        System.out.println(balance + accttype + amount + balance);
     }
     else
     {
        System.out.print(+balance + accttype + amount + balance);
     }

   } //end main
} // end class CheckingAcct

Recommended Answers

All 7 Replies

are you wanting to use Input/Output???

What do you mean by Input/output?

are you wanted to get input from the user and then output the results?

Ok i have gotten stuck on this program and I need help

This program is supposed to calculate the balance of a
checking account after the user has entered
the type of action (withdrawl, deposit)
they would like to do.

My output should be a report that prints the beginning balance, the action (deposit or withdrawl), the amount and the ending balance.

Thank You Guys In Advance.

public class CheckingAcct
{
   public static void main (String [] args)

   {
     double balance;
     double amount;
     char accttype;





     System.out.print("Enter checking account balance:  ");
     balance = Input.readDouble ();
     balance=0;
     System.out.print("Enter account type D=Deposit, W=Withdrawl or    B=Balance to end");
     accttype = Input.readChar ();

     if (accttype.equalsIgnoreCase("d"))
     {
        System.out.print("Enter deposit amount: ");
        amount = Input.readDouble ();
        balance = balance + amount;
     }
     else if (accttype.equalsIgnoreCase("w"))
     {
        System.out.print("Enter withdrawl amount: ");
        amount = Input.readDouble ();
        balance = balance + amount;
        System.out.println(balance + accttype + amount + balance);
     }
     else
     {
        System.out.print(+balance + accttype + amount + balance);
     }

   } //end main
} // end class CheckingAcct

first thing u hav to do is not to assign the value of balance to 0 after reading
it from input.
Since amount and balance are same type (double) the system.out. will calculate their sum and will display if u want them seperate seperate the +
with +","+. and after withdrawl the balance is decresed so
in withdrawl balance=balance-amount
if u just displaying this or wnat to have validations wether balance is becomng
negative so please feel free to ask hope this will cater ur doubts.

Thank you guys so far for your input. I did the suggested changes and I am getting 2 error messages, : char cannot be dereferenced
if (accttype.equalsIgnoreCase("d")) as well as for if(accttype.equalsIgnoreCase("w")).

And yes this is an input/output program.

The program is supposed to ask the user for the checking account balance, amount to witdrawl or deposit and when the user finally hits "B" for balance then it is supposed to give an output of the transaction, amount and balance.

Is there anyone willing to help me more??

Thank you guys so far for your input. I did the suggested changes and I am getting 2 error messages, : char cannot be dereferenced
if (accttype.equalsIgnoreCase("d")) as well as for if(accttype.equalsIgnoreCase("w")).

And yes this is an input/output program.

The program is supposed to ask the user for the checking account balance, amount to witdrawl or deposit and when the user finally hits "B" for balance then it is supposed to give an output of the transaction, amount and balance.

u can just use if(accttype=='B') or not
no need of equalIgnorCase

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.