can u give me this program

  • Thread starter Gopi @ IBM Bangalore Manyata
  • Start date
G

Gopi @ IBM Bangalore Manyata

hi i am new to java
i have one question
if i want to write a program for Bank

here all inputs i should give runtime only(so i have to use Scanner )
first it should ask do u want to open a bank account
banks are two types national and international
it should ask which type of bank u need to open and for national banks
min balance is 10000 and for national its 5000
after that it should choose for bank and then it ask for money
deposite and
account are in two types FB and SB
can i have idea for this please
 
J

John B. Matthews

"Gopi @ IBM Bangalore Manyata said:
hi i am new to java i have one question if i want to write a program
for Bank

here all inputs i should give runtime only(so i have to use Scanner )
first it should ask do u want to open a bank account banks are two
types national and international it should ask which type of bank u
need to open and for national banks min balance is 10000 and for
national its 5000 after that it should choose for bank and then it
ask for money deposite and account are in two types FB and SB can i
have idea for this please

Is this homework? What code have you written so far?
 
A

Arved Sandstrom

John said:
Is this homework? What code have you written so far?

I'm thinking it's more likely that Gopi took on a job at IBM Bangalore as a
Java programmer, and now has to speedily and desperately learn the language.

AHS
 
G

Gopi

my code is like this
package com;

import java.util.ArrayList;
import java.util.Random;

public class Bank {



String AccID;

ArrayList<Bank> national;
ArrayList<Bank> privte;

public String getCustomerID(String bankName,String accType )
{

String randomString;
Random randomGenerator = new Random();
int randomInt=randomGenerator.nextInt();
randomString=Integer.toString(randomInt);
AccID=bankName.concat(randomString);

return AccID;
}





}





package com;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class BankTest {


public static void main(String[] args) throws IOException {
String accType;
String bankType;
String bankName;
String SbankOption;
int bankOption;
// String AccID;
Bank b;
int minibal;


InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);

System.out.println("\nChoose the Account type:\n1.Savings Bank(SB)
\n2.Fixed Deposit(FD)\n");
accType=br.readLine();

System.out.println("\nChoose the type of bank:\n");
System.out.println("1.Nationalised Bank\n2.Private Bank");
bankType=br.readLine();

System.out.println("Choose one of the banks:");

if(bankType.equals("1"))
{
National n=new National();
n.listNationalBanks();
SbankOption=br.readLine();
bankOption=Integer.parseInt(SbankOption);
bankName=n.getBankName(bankOption);
minibal=n.minbal;
b=n.getBankObject(bankName);
}
else
{
Private p=new Private();
p.listPrivateBanks();
SbankOption=br.readLine();
bankOption=Integer.parseInt(SbankOption);
bankName=p.getBankName(bankOption);
minibal=p.minbal;
b=p.getBankObject(bankName);
}



//AccID=b.getCustomerID(bankName,accType);

Customer cust=new Customer();
if(accType.equalsIgnoreCase("1"))
{
cust.openSB(b, minibal);
cust.SBoperations(cust);
}
else
{
cust.openFD(b, minibal);
}

}

}



package com;

import java.util.Random;

public class CITI extends Private{

float rti=(float)7.5;
}



package com;

import java.util.Random;

public class Corporate extends National{
float rti=(float)10;

}


package com;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;






public class Customer {

String AccID;
int AccBal=0;

float FDamt=0;

public void depositMoney() throws NumberFormatException, IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("\nEnter the deposit amount: ");
int amt=Integer.parseInt(br.readLine());
AccBal+=amt;
}

public void withdrawMoney() throws NumberFormatException, IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("\nEnter the withdrawl amount: ");
int amt=Integer.parseInt(br.readLine());
AccBal-=amt;

}

public void viewBalance()
{
System.out.println("\nDear customer, the current balance in your
account is Rs."+AccBal);
}

public void openSB(Bank bb,int minibal) throws NumberFormatException,
IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("\nDeposit money to open SB account: Minimum
amount is Rs."+minibal);
AccBal=Integer.parseInt(br.readLine());

while(AccBal < minibal)
{
System.out.println("Please enter greater than Rs."+minibal);
AccBal=Integer.parseInt(br.readLine());
}
System.out.println("\nSB Account created successfully");

}

public void openFD(Bank bb, int minibal) throws
NumberFormatException, IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("\nEnter the following details to open FD account:
\n");
System.out.println("\nEnter the amount (in Rs.) = ");
FDamt=Float.parseFloat(br.readLine());

while(FDamt < 1000)
{
System.out.println("Please enter the amount greater than or equal
to Rs.1000");
FDamt=Float.parseFloat(br.readLine());
}

System.out.println("Enter the period in months: ");
int period=Integer.parseInt(br.readLine());

System.out.println("\nFD Account created successfully\n\n");
FDdetails(bb,FDamt,period);
}

public void SBoperations(Customer cust) throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);

System.out.println("\nChoose one of the transactions:");

System.out.println("1.Deposit money\n2.Withdraw money\n3.View Balance
\n0.Exit");
String t=br.readLine();

while(!(t.equalsIgnoreCase("0")))
{
if(t.equalsIgnoreCase("1"))
{
cust.depositMoney();
}
else if(t.equalsIgnoreCase("2"))
{
cust.withdrawMoney();
}
else
{
cust.viewBalance();
}
System.out.println("1.Deposit money\n2.Withdraw money\n3.View Balance
\n0.Exit");
t=br.readLine();
}
}


public void FDdetails(Bank bb, float principal, int period)
{
//float rateofinterest;
//float AccountBalance;
float interest;
float time=(float)period/12;
float rti=9;
System.out.println("\nPrincipal Amount = Rs."+principal);
System.out.println("Time period = Rs."+time);
System.out.println("Rate of Interest = "+rti);

interest=(principal*time*rti)/100;
System.out.println("Interest credited after "+period+" months =
Rs."+interest);
float amount=principal+interest;
System.out.println("\nTotal Amount = Rs."+amount);

}
}



package com;

import java.util.Random;

public class HDFC extends Private{

float rti=(float)7;
}


package com;

import java.util.Random;

public class ICICI extends Private{

float rti=(float)8;
}


package com;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.Random;

public class National extends Bank{

final int minbal=5000;
ArrayList<String> nationalbanks = new ArrayList<String>();

public void listNationalBanks()
{

nationalbanks.add("SBI");
nationalbanks.add("Corporate");
nationalbanks.add("Syndicate");
int count =1;
for(String natBank:nationalbanks)
{
System.out.println(count+"."+natBank+"\n");
count++;
}
}

public String getBankName(int bankIndex)
{

return nationalbanks.get(bankIndex);
}

public National getBankObject(String bankName)
{
if(bankName.equalsIgnoreCase("SBI"))
{
SBI b=new SBI();
return b;
}
else if(bankName.equalsIgnoreCase("Corporate"))
{
Corporate b= new Corporate();
return b;
}

else
{
Syndicate b=new Syndicate();
return b;
}

}


}



package com;

import java.util.ArrayList;
import java.util.Iterator;

public class Private extends Bank{

ArrayList<String> privatebanks = new ArrayList<String>();
final int minbal=10000;

public void listPrivateBanks()
{

privatebanks.add("CITI");
privatebanks.add("ICICI");
privatebanks.add("HDFC");
int count =1;
for(String pvtBank:privatebanks)
{
System.out.println(count+"."+pvtBank+"\n");
count++;
}
}

public String getBankName(int bankIndex)
{
return privatebanks.get(bankIndex);
}

public Private getBankObject(String bankName)
{

if(bankName.equalsIgnoreCase("CITI"))
{
CITI b=new CITI();
return b;
}
else if(bankName.equalsIgnoreCase("ICICI"))
{
ICICI b= new ICICI();
return b;
}
else
{
HDFC b=new HDFC();
return b;
}

}
}



package com;


public class SBI extends National{
float rti=(float)9;

}



package com;


public class Syndicate extends National{

float rti=(float)8.5;
}



this is my code but getting some mistakes
 
J

John B. Matthews

Gopi said:
my code is like this
[hundreds of lines of code omitted]
this is my code but getting some mistakes

It's not realistic to expect people to debug hundreds of lines of
ill-formatted, repetitive code with little or no indication of what's
wrong. Consider creating a much shorter example that demonstrates the
problem, as discussed here: <http://sscce.org/>

For the particular case of IndexOutOfBoundsException arising in
subclasses of Bank, note that ArrayList indexes start at zero, not one.

<http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html>
 
L

Lew

Gopi said:
my code is like this
[hundreds of lines of code omitted]
this is my code but getting some mistakes
For the particular case of IndexOutOfBoundsException arising in
subclasses of Bank, note that ArrayList indexes start at zero, not one.

<http://download.oracle.com/javase/6/docs/api/java/util/ArrayList.html>

For the general case, do not use TAB characters to indent Usenet posts. Do
use spaces, up to four per indent level.

In the particular case of (TABs removed):
public class Bank {
String AccID;

ArrayList<Bank> national;
ArrayList<Bank> privte;

public String getCustomerID(String bankName,String accType )
{

String randomString;
Random randomGenerator = new Random();
int randomInt=randomGenerator.nextInt();
randomString=Integer.toString(randomInt);
AccID=bankName.concat(randomString);

return AccID;
}
}

You should not allocate a new 'Random' with each call. Make the generator a
member of the class. Otherwise the "random" sequence starts over with each call.

The 'AccID' variable, on the other hand (OTOH), should NOT be a member
variable - as is, it will be shared by every caller to the same object's
'getCustomerID' method. Also, variable names should start with a lower-case
letter, with one exception that does not apply here. Read the coding
conventions document:
<http://www.oracle.com/technetwork/java/codeconv-138413.html>

Finally, learn to spell "you" and "I". Be professional.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
DewittMill
Top