Switch statement problem

I am doing a question in which I have to make a simple ATM program that can withraw and deposit money as many times as the user wants. To exit the program the user has to hit "x". I have to use a switch statement. Im getting incompatible type errors after compiling it. Can anyone help me? Sorry if the formattings not too good.

***************************************************************************************

//ATM.java

//This program reads in a user's opening balance and performs a withdrawal or a deposit at the request of the user

import java.text.*;

public class ATM

{

public static void main(String args[])

{

int balance;

char withdrawal, deposit, choice;

//Ask for the opening balance

System.out.print("Please enter your opening balance");

balance=UserInput.getInt();

//Find out what the user wants done

System.out.print("What would you like to do? (Withdrawal, Depositor Exit(x))");

choice=UserInput.getChar();

switch(choice){

case "w":

while(balance>0)

System.out.print("How much would you like to withdraw?");

withdrawal=UserInput.getChar();

balance=balance-withdrawal;

System.out.print("Your remaining balance is " + balance);

break;

case "d":

while(balance>0)

System.out.print("How much do you wish to deposit?");

deposit=UserInput.getChar();

balance=balance+deposit;

System.out.print("Your new balance is " + balance);

break;

case "x":

System.out.print("Goodbye and thank you for using this program");

break;

default:

System.out.print("We were not able to process your request, please try again");

break;

}

}

}

[1820 byte] By [Xivilaia] at [2007-11-26 20:20:32]
# 1

Type a reply to the topic using the form below. When finished, you can optionally preview your reply by clicking on the "Preview" button. Otherwise, click the "Post" button to submit your message immediately.

Subject:

Click for bold Click for italics Click for underline Click for code tags

Formatting tips

Message:

Add topic to Watchlist:

Original Message:

Switch statement problem

Xivilai Registered: Mar 3, 2007 9:52 AM Mar 3, 2007 10:06 AM

I am doing a question in which I have to make a simple ATM program that can withraw and deposit money as many times as the user wants. To exit the program the user has to hit "x". I have to use a switch statement. Im getting incompatible type errors after compiling it. Can anyone help me? Sorry if the formattings not too good.

***************************************************************************************

//ATM.java

//This program reads in a user's opening balance and performs a withdrawal or a deposit at the request of the user

import java.text.*;

public class ATM

{

public static void main(String args[])

{

int balance;

char withdrawal, deposit, choice;

//Ask for the opening balance

System.out.print("Please enter your opening balance");

balance=UserInput.getInt();

//Find out what the user wants done

System.out.print("What would you like to do? (Withdrawal, Depositor Exit(x))");

choice=UserInput.getChar();

switch(choice){

case 'w':

while(balance>0)

System.out.print("How much would you like to withdraw?");

withdrawal=UserInput.getChar();

balance=balance-withdrawal;

System.out.print("Your remaining balance is " + balance);

break;

case 'd':

while(balance>0)

System.out.print("How much do you wish to deposit?");

deposit=UserInput.getChar();

balance=balance+deposit;

System.out.print("Your new balance is " + balance);

break;

case 'x':

System.out.print("Goodbye and thank you for using this program");

break;

default:

System.out.print("We were not able to process your request, please try again");

break;

}

}

}

qUesT_foR_knOwLeDgea at 2007-7-10 0:45:05 > top of Java-index,Java Essentials,New To Java...