Shloeb
In the zone
I have just started java classes 4 days ago. And i have been given an assignment. To make that assignment i have to use a command similar to goto statement.
Assignment is:
Design a class to represent a bank account
Data types
-Name of the depositor
-Account number
-Type of account
-Balance amount in the account
Methods
-To assign initial values
-To deposit an amount
-To withdraw an amount after checking balance
-To display the name & balance
I have made this program
The main problem here is that i need a command to jump to label xyz. As i am new to JAVA so i don't know. goto was supported by earlier java compilers but not know. So can anyone give me an alternative?
Assignment is:
Design a class to represent a bank account
Data types
-Name of the depositor
-Account number
-Type of account
-Balance amount in the account
Methods
-To assign initial values
-To deposit an amount
-To withdraw an amount after checking balance
-To display the name & balance
I have made this program
Code:
import java.io.*;
class bank
{
String name,actype;
int acno,bal,amt;
bank()
{
StringBuffer name=new StringBuffer("Satinder Pal Singh");
acno=101023;
StringBuffer actype=new StringBuffer("Savings");
bal=10000;
}
void dep()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("What amount you want to deposit:");
amt=Integer.parseInt(br.readLine());
bal=bal+amt;
}
void wdraw()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Your Balance="+bal);
System.out.print("What amount you want to withdraw:");
amt=Integer.parseInt(br.readLine());
bal=bal-amt;
if(bal<amt)
{
System.out.println("Not sufficient balance");
//xyz;
}
}
void disp()
{
System.out.println("Name:"+name);
System.out.println("Balance:"+bal);
}
void dbal()
{
System.out.println("Balance:"+bal);
}
}
class mgmt
{
public static void main(String ar[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n;
bank b1=new bank();
b1.disp();
xyz: System.out.println("To withdraw press 1");
System.out.println("To deposit press 2");
n=Integer.parseInt(br.readLine());
if(n==1)
{
b1.wdraw();
b1.dbal();
}
else if(n==2)
{
b1.dep();
b1.dbal();
}
else
{
System.out.println("Please enter a valid choice");
//xyz;
}
}
}