NOTE: Use the Account class codes in the section below these questions.
|
CheckingAccountDemo.java import java.util.*; public class CheckingAccountDemo { public static void main(String[] args) { double balance; String ownerName; int accountNumber; Scanner input = new Scanner(System.in); System.out.println("Enter the name of owner of account: "); ownerName = input.nextLine(); System.out.println("Enter the account Number: "); accountNumber = input.nextInt(); System.out.println("Enter the account balance: "); balance = input.nextDouble(); CheckingAccount object1 = new CheckingAccount(accountNumber,ownerName,balance); //calling displayAccount method object1.displayAccount(); System.out.println("Enter amount to be Deposit:"); double deposit_amount=input.nextDouble(); //calling deposit account object1.depositAmount(deposit_amount); object1.displayAccount(); System.out.println("Enter amount to be Withdraw:"); double withdraw_amount=input.nextDouble(); //calling withdrawAmount method if(object1.withdrawAmount(withdraw_amount)){ System.out.println("Amount withdrawn successfully"); } else { System.out.println("Please check enter amount with current balance"); } object1.displayAccount(); } } |
|
CheckingAccount.java public class CheckingAccount { private int AccNumber; private String Owner; private double Balance; CheckingAccount(int AccNumber, String Owner, double Balance) { if(Balance<0) { System.err.println("Error. The Balance can't be negative"); this.Balance = 0.0; } else this.Balance = Balance; this.AccNumber = AccNumber; this.Owner = Owner; } // setter functions void setAccNumber(int AccNumber) { this.AccNumber = AccNumber; } void setOwner(String Owner) { this.Owner = Owner; } void setBalance(double Balance) { if(Balance<0) { System.err.println("Error. The Balance can't be negative"); this.Balance = 0.0; } else this.Balance = Balance; } //getter functions int getAccNumber() { return this.AccNumber; } String getOwner() { return this.Owner; } double getBalance() { return this.Balance; } //method for display account details void displayAccount(){ System.out.println("Name : "+getOwner()); System.out.println("Account number : "+ getAccNumber()); System.out.println("Available balance : "+getBalance()); } //method for deposit void depositAmount(double value){ if(value<0){ System.out.println("Amount should be positive"); } else{ this.Balance+=value; } } //method for withdraw boolean withdrawAmount(double value) { if(value<0 || this.Balance<value) { return false; } else { this.Balance-=value; return true; } } } |
in our CheckingAccountDemo class:
first we create an array AccountArray for storing 10 accounts
then we ask user to enter details of 10 account and add them to array
then we create an infinite while loop that only terminates when user enters exit
inside the loop we ask the user to enter account owner name or enter exit to quit
if the user enters a account owner name we search the array AccountArray for the account.
if account is not found we display account not found
else we ask user to deposit or withdraw money and perform deposit or withdrawal according to users choice
outside the while loop we display the details off all the accounts in array using for loop.
CheckingAccountDemo.java:
import java.util.Scanner;
public class CheckingAccountDemo {
public static void main(String[] args)
{
//array for storing 10 accounts
CheckingAccount[] AccountArray = new CheckingAccount[10];
Scanner input = new Scanner(System.in);
//variables
double balance;
String ownerName;
int accountNumber;
System.out.println("Enter 10 account details");
//asking user for 10 account details,creating each account and adding it to array
for (int i = 0; i < 10; i++) {
System.out.println("Enter the name of owner of account: ");
ownerName = input.nextLine();
System.out.println("Enter the account Number: ");
accountNumber = Integer.parseInt(input.nextLine());
System.out.println("Enter the account balance: ");
balance = Double.parseDouble(input.nextLine());
AccountArray[i] = new CheckingAccount(accountNumber, ownerName, balance);
}
String name;
//infinite loop that only terminates when user enters exit
while (true) {
//asking user to enter account owner name or exit
System.out.println("Enter account owner name or enter exit to quit: ");
name = input.nextLine();
if (name.equals("exit")) { //if user enters exit we break the loop
break;
} else {
CheckingAccount account = searchAccount(AccountArray, name); //calling function to search account in array
//if account not found
if (account == null) {
System.out.println("Account not found");
} else {
//asking user to enter 0 to withdraw money and 1 to deposit money
System.out.println("Enter 1 to deposit or 0 to withdraw: ");
int choice = Integer.parseInt(input.nextLine());
if (choice == 1) {//if user enters 1
account.displayAccount();
System.out.println("Enter amount to be Deposit:");
double deposit_amount = Double.parseDouble(input.nextLine());
account.depositAmount(deposit_amount);
account.displayAccount();
} else {
account.displayAccount();
System.out.println("Enter amount to be Withdraw:");
double withdraw_amount = Double.parseDouble(input.nextLine());
//calling withdrawAmount method
if (account.withdrawAmount(withdraw_amount)) {
System.out.println("Amount withdrawn successfully");
} else
{
System.out.println("Please check enter amount with current balance");
}
account.displayAccount();
}
}
}
}
// displaying details of all accounts in the array
for (int i=0;i<10;i++){
AccountArray[i].displayAccount();
System.out.println();
}
}
//function for searchiong account in array
private static CheckingAccount searchAccount(CheckingAccount[] accountArray, String name) {
for (int i = 0; i < 10; i++) {
if (accountArray[i].getOwner().equals(name)) {
return accountArray[i];
}
}
return null;
}
}
NOTE: Use the Account class codes in the section below these questions. Modify the main method...
Use the Java codes below (Checking Account and Checking Account Demo), and work on these problems. You have to do both of your java codes based on the two provided Java codes. Create one method for depositing and one for withdrawing. The deposit method should have one parameter to indicate the amount to be deposited. You must make sure the amount to be deposited is positive. The withdraw method should have one parameter to indicate the amount to be withdrawn...
WHERE in this code should you put the main method so that the code will compile WITHOUT changing anything else in the code? Simply adding the main method only? public class Account { private String name; private double balance; public Account(String name, double balance) { this.name = name; if (balance > 0.0) this.balance = balance; } public void deposit(double depositAmount) { if (depositAmount > 0.0) balance += depositAmount; } public double getBalance() { return balance; } public String...
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package checkingaccounttest; // Chapter 9 Part II Solution public class CheckingAccountTest { public static void main(String[] args) { CheckingAccount c1 = new CheckingAccount(879101,3000); c1.deposit(350); c1.deposit(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.withdraw(350); c1.withdraw(220); c1.withdraw(100); c1.deposit(1100); c1.deposit(700); c1.deposit(1000); System.out.println(c1); System.out.println("After calling computeMonthlyFee()"); c1.computeMonthlyFee(); System.out.println(c1); } } class BankAccount { private int...
I need to update the code listed below to meet the criteria listed on the bottom. I worked on it a little bit but I could still use some help/corrections! import java.util.Scanner; public class BankAccount { private int accountNo; private double balance; private String lastName; private String firstName; public BankAccount(String lname, String fname, int acctNo) { lastName = lname; firstName = fname; accountNo = acctNo; balance = 0.0; } public void deposit(int acctNo, double amount) { // This method is...
TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...
Point out errors in the following codes and correct them public class CheckingAccount { // Create attributes accountNum, Balance private int accountNum; // Account Number private double balance; // Account balance // Constructor public void CheckingAccount(int aNum, double balance) { // Call setters to initialize attribute values setAccountNumber(aNum); setBalance; } // Setters public void setAccountNumber(int aNum) { if (accountNum >= 100) { accountNum = aNum; }...
*Step1: -Create UML of data type classes: reuse from lab3 for class Account, CheckingAccount and SavingAccount -Read the requirement of each part; write the pseudo-code in a word document by listing the step by step what you suppose to do in main() and then save it with the name as Lab4_pseudoCode_yourLastName *Step2: -start editor eClipse, create the project→project name: FA2019_LAB4PART1_yourLastName(part1) OR FA2019_LAB4PART2_yourLastName (part2) -add data type classes (You can use these classes from lab3) Account_yourLastName.java CheckingAccount_yourLastName.java SavingAccount_yourLastName.java -Add data structure...
Hello everybody. Below I have attached a code and we are
supposed to add comments explaining what each line of code does.
For each method add a precise description of its purpose, input and
output. Explain the purpose of each member variable. . Some help
would be greaty appreciated. (I have finished the code below with
typing as my screen wasnt big enough to fit the whole code
image)
}
public void withdrawal (double amount) {
balance -=amount;
}...
Look at the Account class below and write a main method in a different class to briefly experiment with some instances of the Account class.Using the Accountclass as a base class, write two derived classes called SavingsAccountand CurrentAccount.ASavingsAccountobject, in addition to the attributes of an Account object, should have an interest variable and a method which adds interest to the account. ACurrentAccount object, in addition to the instance variables of an Account object, should have an overdraft limit variable. Ensure...
According to the following information, define Account, CheckingAccount, and TestPart1 classes. 1. Account and CheckingAccount classes Account - number: int - openDate: String - name: String - balance: double + Account(int, String, String, double) + deposit(double): void + withdraw (double): boolean + transferTo(Account, double): int + toString(): String CheckingAccount + CheckingAccount(int, String, String, double) + transferTo(Account, double): int Given the above UML diagam, define Account and CheckingAccount classes as follow: Account (8 points) • public Account(int nu, String op, String...