Using java and object oriented design, create a program for a banking system to
ID: 3737794 • Letter: U
Question
Using java and object oriented design, create a program for a banking system to provide cash to a customer in five different domains. There should be at least one constructor and different methods for each domain. The default constructor will provides cash in terms of 20s. The rest will be as follows to complete the amount: minimum is 20 and max is $400 can be taken out
$1 $5 and $20
$1 $5 and $20 if the amount is less than 100. For greater than 100 and less than 200, puts $20 and 100 and $5
If greater than 200 and less than 300 uses option 1 and 2 more $100 bills
For 400, the customer select his/her own domination to complete the amount
Explanation / Answer
ScreenShot
-------------------------------------------------------------------------------------------------------------
Program:-
//Header files
import java.util.*;
import java.lang.*;
import java.io.*;
//Banking class
class banking{
//Member variable
int amount;
//constructor
banking(int value){
amount=value;
}
//Method for less than 100
public void calculateLessthan100(){
int temp=amount;
int twenties=temp/20;
temp=temp%20;
int fives=temp/5;
temp=temp%5;
int> System.out.println("Change of "+amount+" is "+twenties+" of $20 and "+fives+" of $5 and "+ones+" of $1.");
}
//Method for less than 200
public void calculateLessthan200(){
int temp=amount;
int hundreds=temp/100;
temp=temp%100;
int twenties=temp/20;
temp=temp%20;
int fives=temp/5;
System.out.println("Change of "+amount+" is "+hundreds+" of $100 and "+twenties+" of $20 and "+fives+" of $5.");
}
//Method for less than 300
public void calculateLessthan300(){
int temp=amount;
int hundreds=temp/100;
temp=temp%100;
int twenties=temp/20;
temp=temp%20;
int fives=temp/5;
temp=temp%5;
int> System.out.println("Change of "+amount+" is "+hundreds+" of $100 and "+twenties+" of $20 and "+fives+" of $5 "+ones+" of $1.");
}
//Method upto 400
public void calculateFor400(){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the denomination you wanted :");
int denomination=sc.nextInt();
int change=amount/denomination;
System.out.println("Change of "+amount+" is "+change+" of $"+denomination+".");
}
}
//main class
class Ideone
{
//Main method
public static void main (String[] args) throws java.lang.Exception
{
//variable declaration
int amount;
//Scanner to read input
Scanner sc=new Scanner(System.in);
System.out.println("Enter the amount needed :");
amount=sc.nextInt();
//check the amount from 20-400
if(amount<20 || amount>400){
System.out.println("Please enter the amount from 20-400.");
}
//Otherwise call each method for change
else{
//Class object creation
banking b=new banking(amount);
//method for less than100 calculation
if(amount<100){
b.calculateLessthan100();
}
//method for less than200 calculation
else if(amount>=100 && amount<200 ){
b.calculateLessthan200();
}
//method for less than300 calculation
else if(amount>=200 && amount<300 ){
b.calculateLessthan300();
}
else if(amount>=300 && amount<=400 ){
b.calculateFor400();
}
}
}
}
-----------------------------------------------------------------------------------------------
Output:-
------------------------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.