Learning coding means GreatToCode Be more than a Coder ! Greattocode , Join GreatToCode Community,1000+ Students Trusted On Us .If You want to learn coding, Then GreatToCode Help You.No matter what It Takes !


CODE YOUR WAY TO A MORE FULFILLING And HIGHER PAYING CAREER IN TECH, START CODING FOR FREE Camp With GreatToCode - Join the Thousands learning to code with GreatToCode
Interactive online coding classes for at-home learning with GreatToCode . Try ₹Free Per Month Coding Classes With The Top Teachers . design a class for bank . bank class support following operations . a) deposit a certain amount into an account . b)withdraw a certain amount from an account c) return a balance value specifying the amount with details.

design a class for bank . bank class support following operations . a) deposit a certain amount into an account . b)withdraw a certain amount from an account c) return a balance value specifying the amount with details.

Become More Then A coder | Learn & Start Coding Now.
  1. import java.util.Scanner;  
  2. class BankDetails {  
  3.     private String accno;  
  4.     private String name;  
  5.     private String acc_type;  
  6.     private long balance;  
  7.     Scanner sc = new Scanner(System.in);  
  8.     //method to open new account  
  9.     public void openAccount() {  
  10.         System.out.print("Enter Account No: ");  
  11.         accno = sc.next();  
  12.         System.out.print("Enter Account type: ");  
  13.         acc_type = sc.next();  
  14.         System.out.print("Enter Name: ");  
  15.         name = sc.next();  
  16.         System.out.print("Enter Balance: ");  
  17.         balance = sc.nextLong();  
  18.     }  
  19.     //method to display account details  
  20.     public void showAccount() {  
  21.         System.out.println("Name of account holder: " + name);  
  22.         System.out.println("Account no.: " + accno);  
  23.         System.out.println("Account type: " + acc_type);  
  24.         System.out.println("Balance: " + balance);  
  25.     }  
  26.     //method to deposit money  
  27.     public void deposit() {  
  28.         long amt;  
  29.         System.out.println("Enter the amount you want to deposit: ");  
  30.         amt = sc.nextLong();  
  31.         balance = balance + amt;  
  32.     }  
  33.     //method to withdraw money  
  34.     public void withdrawal() {  
  35.         long amt;  
  36.         System.out.println("Enter the amount you want to withdraw: ");  
  37.         amt = sc.nextLong();  
  38.         if (balance >= amt) {  
  39.             balance = balance - amt;  
  40.             System.out.println("Balance after withdrawal: " + balance);  
  41.         } else {  
  42.             System.out.println("Your balance is less than " + amt + "\tTransaction failed...!!" );  
  43.         }  
  44.     }  
  45.     //method to search an account number  
  46.     public boolean search(String ac_no) {  
  47.         if (accno.equals(ac_no)) {  
  48.             showAccount();  
  49.             return (true);  
  50.         }  
  51.         return (false);  
  52.     }  
  53. }  
  54. public class BankingApp {  
  55.     public static void main(String arg[]) {  
  56.         Scanner sc = new Scanner(System.in);  
  57.         //create initial accounts  
  58.         System.out.print("How many number of customers do you want to input? ");  
  59.         int n = sc.nextInt();  
  60.         BankDetails C[] = new BankDetails[n];  
  61.         for (int i = 0; i < C.length; i++) {  
  62.             C[i] = new BankDetails();  
  63.             C[i].openAccount();  
  64.         }  
  65.         // loop runs until number 5 is not pressed to exit  
  66.         int ch;  
  67.         do {  
  68.             System.out.println("\n ***Banking System Application***");  
  69.             System.out.println("1. Display all account details \n 2. Search by Account number\n
  70.  3. Deposit the amount \n 4. Withdraw the amount \n 5.Exit ");  
  71.             System.out.println("Enter your choice: ");  
  72.             ch = sc.nextInt();  
  73.                 switch (ch) {  
  74.                     case 1:  
  75.                         for (int i = 0; i < C.length; i++) {  
  76.                             C[i].showAccount();  
  77.                         }  
  78.                         break;  
  79.                     case 2:  
  80.                         System.out.print("Enter account no. you want to search: ");  
  81.                         String ac_no = sc.next();  
  82.                         boolean found = false;  
  83.                         for (int i = 0; i < C.length; i++) {  
  84.                             found = C[i].search(ac_no);  
  85.                             if (found) {  
  86.                                 break;  
  87.                             }  
  88.                         }  
  89.                         if (!found) {  
  90.                             System.out.println("Search failed! Account doesn't exist..!!");  
  91.                         }  
  92.                         break;  
  93.                     case 3:  
  94.                         System.out.print("Enter Account no. : ");  
  95.                         ac_no = sc.next();  
  96.                         found = false;  
  97.                         for (int i = 0; i < C.length; i++) {  
  98.                             found = C[i].search(ac_no);  
  99.                             if (found) {  
  100.                                 C[i].deposit();  
  101.                                 break;  
  102.                             }  
  103.                         }  
  104.                         if (!found) {  
  105.                             System.out.println("Search failed! Account doesn't exist..!!");  
  106.                         }  
  107.                         break;  
  108.                     case 4:  
  109.                         System.out.print("Enter Account No : ");  
  110.                         ac_no = sc.next();  
  111.                         found = false;  
  112.                         for (int i = 0; i < C.length; i++) {  
  113.                             found = C[i].search(ac_no);  
  114.                             if (found) {  
  115.                                 C[i].withdrawal();  
  116.                                 break;  
  117.                             }  
  118.                         }  
  119.                         if (!found) {  
  120.                             System.out.println("Search failed! Account doesn't exist..!!");  
  121.                         }  
  122.                         break;  
  123.                     case 5:  
  124.                         System.out.println("See you soon...");  
  125.                         break;  
  126.                 }  
  127.             }  
  128.             while (ch != 5);  
  129.         }  
  130.     }  

import java.io.*;
class Slip7
{
public static void main(String[] args)throws Exception
{
int ch,n=0,i=0,b;
FileInputStream fin=new FileInputStream("abc.txt");
while((ch=fin.read())!=-1)
{
n=n+1;
//System.out.println((char)ch);
}
char str[]=new char[n];
fin.close();
FileInputStream fin1=new FileInputStream("abc.txt");
while((b=fin1.read())!=-1)
{
str[i]=(char)b;
i++;
}
for(i=n-1;i>=0;i--)
{
System.out.print(str[i]);
}
fin.close();
}
}

A Java program that creates a Bank Account with withdraw, deposit, and intrest functions. And a tester class, that tests the SavingsAccount class..

/SavingsAccount

public class SavingsAccount { private double balance; private double interest; public SavingsAccount() { balance = 0; interest = 0; } public SavingsAccount(double initialBalance, double initialInterest) { balance = initialBalance; interest = initialInterest; } public void deposit(double amount) { balance = balance + amount; } public void withdraw(double amount) { balance = balance - amount; } public void addInterest() { balance = balance + balance * interest; } public double getBalance() { return balance; } }

saving account tester.java

public class SavingsAccountTester
{
public static void main(String[] args)
{
SavingsAccount jimmysSavings = new SavingsAccount(1000, 0.10);
jimmysSavings.withdraw(250);
jimmysSavings.deposit(400);
jimmysSavings.addInterest();
System.out.println(jimmysSavings.getBalance());
System.out.println("Expected: 1265.0");
//1000-250=750 => 750+400=1150 => 1150+1150*0.10=1265.0
}
}

Post a Comment

0 Comments

•Give The opportunity to your child with GreatToCode Kid's • Online Coding Classes for Your Kid • Introduce Your kid To the world's of coding
•Fuel You Career with our 100+ Hiring Partners, Advance Your Career in Tech with GreatToCode. •Join The Largest Tech and coding Community and Fast Forward Your career with GreatToCode. •10000+ Learner's+ 90 % placement Guarantee. • Learning Coding is Better with the GreatToCode community .
•Greattocode Kid's •GreatToCode Career •GreatToCode Interview •GreatToCode Professional •GreatToCode for schools •GreatToCode For colleges •GreatToCods For Businesses.
Are you ready to join the millions of people learning to code? GreatToCode Pass is your one-stop-shop to get access to 1000+ courses, top-notch support, and successful job placement. What are you waiting for? Sign up now and get your future in motion with GreatToCode Pass.