Question
This is in Java Porgramming. I need to write a JavaDoc (comments) as well as a UML for the following: Account public class Account {
This is in Java Porgramming. I need to write a JavaDoc (comments) as well as a UML for the following:
Account
public class Account {
private long accNumber;
private Person accHolder;
private double balance;
public Account(long accNum, Person p, double bal) {
accNumber = accNum;
accHolder = p;
balance = bal;
}
public long getAccNumber() {
return accNumber;
}
public Person getAccHolder() {
return accHolder;
}
public double getBalance() {
return balance;
}
public String getName() {
return accHolder.getName();
}
public String getEmailAddress() {
return accHolder.getEmailAddress();
}
public long getPhoneNum() {
return accHolder.getPhoneNumber();
}
public void deposit(double deposit) {
balance = balance + deposit;
}
public int withdraw(double amountWithdrawn) {
if (balance >= amountWithdrawn)
balance = balance - amountWithdrawn;
else
System.out.println("not enough fund");
return (int) balance;
}
}
Bank
mport java.util.Scanner;
public class Bank {
private String bankName;
Bank(String name) {
bankName = name;
}
public void generateAccountDetails(Account[] accounts, int numAccHolders) {
Scanner in = new Scanner(System.in);
for (int i = 0; i < numAccHolders; i++) {
System.out.println("Enter details of account holder " + (i + 1));
System.out.println("=================================");
System.out.println("Enter account number : ");
long accNum = in.nextLong();
System.out.println("Enter First name: ");
String fName = in.next();
System.out.println("Enter Last name: ");
String lName = in.next();
System.out.println("Enter phone Number: ");
long ph = in.nextLong();
System.out.println("Enter Email address: ");
String email = in.next();
Person accHolder = new Person(fName, lName, ph, email); // creating accHolder which is an object of Person
// class
System.out.println("Enter opening balance : ");
double bal = in.nextDouble();
accounts[i] = new Account(accNum, accHolder, bal); // creating Account object which be stored in i-th
// position of accounts array
}
}
public void printAccountDetails(Account[] accounts, int num) {
System.out.println(" " + bankName + "'s Banking System");
System.out.println("*********************");
for (int i = 0; i < num; i++)
System.out.println("Account Number: "+accounts[i].getAccNumber()+ " Name: "+accounts[i].getName()+" Phone Number: "+accounts[i].getPhoneNum()+ " Email Address: "+accounts[i].getEmailAddress()+" Balance: "+accounts[i].getBalance());
}
}
Person
public class Person {
private String firstName;
private String lastName;
private long phoneNum;
private String emailAddress;
Person(String fName, String lName, long phone, String email) {
firstName = fName;
lastName = lName;
phoneNum = phone;
emailAddress = email;
}
public String getName() {
return (firstName + " " + lastName);
}
public long getPhoneNumber() {
return phoneNum;
}
public String getEmailAddress() {
return emailAddress;
}
}
BankTest
import java.util.Scanner;
public class BankTest {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String choice = new String("a");
char opt = choice.charAt(0);
int index = -1;
double amnt;
System.out.println("Enter your name : ");
String name = in.next();
System.out.print("How many account holders are there in your banking System : ");
int num = in.nextInt();
Bank bank = new Bank(name);
Account[] accounts = new Account[num];
bank.generateAccountDetails(accounts, num);
while (opt != 'n') {
System.out.println("d: Deposit w: Withdraw p: Print all accounts n:Quit Enter your option : ");
choice = in.next().toLowerCase();
opt = choice.charAt(0);
if (opt == 'd') {
do {
System.out.println("Enter account index : ");
index = in.nextInt();
if (index >= num)
System.out.println("Enter an index less than " + num);
} while (index > num);
System.out.println("Enter deposit amount: ");
amnt = in.nextDouble();
accounts[index].deposit(amnt);
} else if (opt == 'w') {
do {
System.out.println("Enter account index : ");
index = in.nextInt();
if (index >= num)
System.out.println("Enter an index less than " + num);
} while (index > num);
System.out.println("Enter withdrawal amount: ");
amnt = in.nextDouble();
int res = accounts[index].withdraw((int)amnt);
if (res == -1)
System.out.println("Insufficient funds");
} else if (opt == 'p') {
bank.printAccountDetails(accounts, num);
} else if (opt == 'n') {
System.out.println("GOOD BYE");
} else {
System.out.println("Wrong choice. try again");
}
}
in.close();
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started