can u give me this program

  • Follow


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
0
Reply Gopi 9/23/2010 6:44:27 PM

In article 
<45c0fe82-50db-407d-a4df-3c96c4deced8@u5g2000prn.googlegroups.com>,
 "Gopi @ IBM Bangalore Manyata" <lavudyagopi27@gmail.com> wrote:

> 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?

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
0
Reply nospam59 (9762) 9/23/2010 11:50:31 PM


John B. Matthews wrote:
> In article
> <45c0fe82-50db-407d-a4df-3c96c4deced8@u5g2000prn.googlegroups.com>,
> "Gopi @ IBM Bangalore Manyata" <lavudyagopi27@gmail.com> wrote:
>
>> 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?

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
-- 
Before a man speaks it is always safe to assume that he is a fool.
After he speaks, it is seldom necessary to assume it. -- H.L. Mencken 


0
Reply dcest61 (384) 9/24/2010 1:19:08 AM


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
0
Reply lavudyagopi27 9/24/2010 6:54:14 AM

In article 
<ad9549fd-414d-4118-852d-9d32834019dd@u13g2000vbo.googlegroups.com>,
 Gopi <lavudyagopi27@gmail.com> wrote:

> 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>

-- 
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
0
Reply nospam59 (9762) 9/24/2010 10:10:04 AM

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

John B. Matthews wrote:
> 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.

-- 
Lew
0
Reply noone7 (3512) 9/24/2010 12:13:12 PM

On Thu, 23 Sep 2010 11:44:27 -0700 (PDT), "Gopi @ IBM Bangalore
Manyata" <lavudyagopi27@gmail.com> wrote, quoted or indirectly quoted
someone who said :

>if i want to write a program for Bank

No you don't.  No bank would use a program that simplistic.

See http://mindprod.com/jgloss/homework.html
-- 
Roedy Green Canadian Mind Products
http://mindprod.com

You encapsulate not just to save typing, but more importantly, to make it easy and safe to change the code later, since you then need change the logic in only one place. Without it, you might fail to change the logic in all the places it occurs.
0
Reply see_website (4858) 9/24/2010 2:51:36 PM

6 Replies
199 Views

(page loaded in 0.12 seconds)

Similiar Articles:













7/29/2012 6:18:32 PM


Reply: