Suppose the bank wanted to keep track of the total number of deposits and withdrawals (separately) for each day, and the total amount deposited and withdrawn. Write code to do this as follows:
import java.util.*;
public class Accounts {
//private static variables
private static int number_of_deposits=0;
private static int number_of_withdrawals=0;
private static int total_amount_of_deposits=0;
private static int total_amount_of_withdrawals=0;
//other instance variables
public double balance=0;
public String name;
public String account_number;
//public accessor methods
public static int getNumberOfDeposits(){
return number_of_deposits;
}
public static int getNumberOfWithdrawals(){
return number_of_withdrawals;
}
public static int getTotalAmountOfWithdrawals(){
return total_amount_of_withdrawals;
}
public static int getTotalAmountOfDeposits(){
return total_amount_of_deposits;
}
public double getBalance(){
return this.balance;
}
public String getName(){
return this.name;
}
public String getAccountNumber(){
return this.account_number;
}
//toString method
public String toString(){
return ("\nName : "+this.getName()+" Account Number :
"+this.getAccountNumber()+" Balane : "+this.getBalance());
}
//withdraw and deposit methods
public void withdraw(double amount){
if(this.balance>=amount){
number_of_withdrawals++;
total_amount_of_withdrawals+=amount;
this.balance-=amount;
}
else{
System.out.println("\nInsufficient balance\n");
}
}
public void deposit(double amount){
number_of_deposits++;
total_amount_of_deposits+=amount;
this.balance+=amount;
}
//main method
public static void main(String args[]){
int ch=1;
Accounts a1=new Accounts();
Accounts a2=new Accounts();
//Reading basic details
Scanner data=new Scanner(System.in);
System.out.println("\nEnter details of Account 1 :\n");
System.out.println("\nName : ");
a1.name=data.next();
System.out.println("\nAccount Number : ");
a1.account_number=data.next();
System.out.println("\nEnter details of Account 2 :\n");
System.out.println("\nName : ");
a2.name=data.next();
System.out.println("\nAccount Number : ");
a2.account_number=data.next();
//loop
do{
int ch1;
System.out.println("\n------------Choose Account-------------\n1.
Acccount 1\n2 Account 2\n");
ch1=Integer.parseInt(data.next());
switch(ch1){
case 1:
System.out.println("\n1.Deposit\n2.Withdraw\n");
switch(Integer.parseInt(data.next())){
case 1:
System.out.println("\nEnter amount to deposit : ");
a1.deposit(Integer.parseInt(data.next()));
break;
case 2:
System.out.println("\nEnter amount to withdraw : ");
a1.withdraw(Integer.parseInt(data.next()));
break;
}
break;
case 2:
System.out.println("\n1.Deposit\n2.Withdraw\n");
switch(Integer.parseInt(data.next())){
case 1:
System.out.println("\nEnter amount to deposit : ");
a2.deposit(Integer.parseInt(data.next()));
break;
case 2:
System.out.println("\nEnter amount to withdraw : ");
a2.withdraw(Integer.parseInt(data.next()));
break;
}
break;
}
System.out.println("\nDo you want to continue ,1 to continue ,any
other number to stop : ");
ch=Integer.parseInt(data.next());
}while(ch==1);
//display the details of deposit and withdrwals
System.out.println("\nNumber of Deposits :
"+getNumberOfDeposits());
System.out.println("\nNumber of Withdrawals :
"+getNumberOfWithdrawals());
System.out.println("\nTotal Amount of Deposits :
"+getTotalAmountOfDeposits());
System.out.println("\nTotal Amount of Withdrawals :
"+getTotalAmountOfWithdrawals());
}
}
-------------------------------------------handle one day method------------------------------
public static void
handleOneDay(Accounts a1,Accounts a2){
Scanner data=new Scanner(System.in);
int ch1;
System.out.println("\n------------Choose Account-------------\n1.
Acccount 1\n2 Account 2\n");
ch1=Integer.parseInt(data.next());
switch(ch1){
case 1:
System.out.println("\n1.Deposit\n2.Withdraw\n");
switch(Integer.parseInt(data.next())){
case 1:
System.out.println("\nEnter amount to deposit : ");
a1.deposit(Integer.parseInt(data.next()));
break;
case 2:
System.out.println("\nEnter amount to withdraw : ");
a1.withdraw(Integer.parseInt(data.next()));
break;
}
break;
case 2:
System.out.println("\n1.Deposit\n2.Withdraw\n");
switch(Integer.parseInt(data.next())){
case 1:
System.out.println("\nEnter amount to deposit : ");
a2.deposit(Integer.parseInt(data.next()));
break;
case 2:
System.out.println("\nEnter amount to withdraw : ");
a2.withdraw(Integer.parseInt(data.next()));
break;
}
break;
}
}
Suppose the bank wanted to keep track of the total number of deposits and withdrawals (separately)...
What if you had to write a program that would keep track of a list of rectangles? This might be for a house painter to use in calculating square footage of walls that need paint, or for an advertising agency to keep track of the space available on billboards. The first step would be to define a class where one object represents one rectangle's length and width. Once we have class Rectangle, then we can make as many objects of...
Instructions We're going to create a program which will allow the user to add values to a list, print the values, and print the sum of all the values. Part of this program will be a simple user interface. 1. In the Program class, add a static list of doubles: private statie List<double> _values new List<double>) this is the list of doubles well be working with in the program. 2. Add ReadInteger (string prompt) , and ReadDouble(string prompt) to the...
Java coding help! Write a program to simulate a bank which includes the following. Include a commented header section at the top of each class file which includes your name, and a brief description of the class and program. Create the following classes: Bank Customer Account At a minimum include the following data fields for each class: o Bank Routing number Customer First name Last name Account Account number Balance Minimum balance Overdraft fee At a minimum write the following...
1-Suppose you write an application in which one class contains code that keeps track of the state of a board game, a separate class sets up a GUI to display the board, and a CSS is used to control the stylistic details of the GUI (for example, the color of the board.) This is an example of a.Duck Typing b.Separation of Concerns c.Functional Programming d.Polymorphism e.Enumerated Values 2-JUnit assertions should be designed so that they a.Fail (ie, are false) if...
In C++ Write a program that contains a class called VideoGame. The class should contain the member variables: Name price rating Specifications: Dynamically allocate all member variables. Write get/set methods for all member variables. Write a constructor that takes three parameters and initializes the member variables. Write a destructor. Add code to the destructor. In addition to any other code you may put in the destructor you should also add a cout statement that will print the message “Destructor Called”....
solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate and balance. The class constructor should accept the amount of the savings account's starting balance. The class should also have methods for subtracting the amount of a withdrawal, adding the amount of a deposit, and adding the amount of monthly twelve. To add the monthly interest rate to the balance,...
7. Programming Problem: In this problem we are trying to model a repair service that can repair Cars and Computers. Even though the Car and Computer are different products, they have common repair methods that can be abstracted in an interface. Please complete the interface and the classes by adding the required methods, as per the problem description. Partially complete code is provided as shown below A. Create an interface called Mechanism. This interface has two methods. The first method...
Java 1. Create an application named NumbersDemo whose main() method holds two integer variables. Assign values to the variables. In turn, pass each value to methods named displayTwiceTheNumber(), displayNumberPlusFive(), and displayNumberSquared(). Create each method to perform the task its name implies. 2. Modify the NumbersDemo class to accept the values of the two integers from a user at the keyboard. This is the base code given: public class NumbersDemo { public static void main (String args[]) { // Write your...
Anyone helps me in a Java Languageif it it is possible thanks. Write a class called Player that holds the following information: Team Name (e.g., Ravens) . Player Name (e.g., Flacco) . Position's Name (e.g. Wide reciver) . Playing hours per week (e.g. 30 hours per week). Payment Rate (e.g., 46 per hour) . Number of Players in the Team (e.g. 80 players) . This information represents the class member variables. Declare all variables of Payer class as private except...
java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...