Hey guys!
So i have this assignment where i need to write a program to manage some bank accounts and i'm completly lost. This is what I've got so far
class Customer { final String firstName; final String lastName; final String phoneNumber; Customer(String firstName,String lastName,String phoneNumber){ this.firstName = firstName; this.lastName = lastName; this.phoneNumber = phoneNumber; } static Customer readCustomer { String firstName = In.readString(); String lastName = In.readString(); String phoneNumber = In.readString(); if(In.done()) return new Customer(firstName,lastName, phoneNumber); else return null; } void print() { Out.format("%-15s %-15s %-15s", firstName,lastName,phoneNumber); } } class Account { final int accountNo; final double overdraft; final double accountBalance; Account(int accountNo,double overdraft,double accountBalance) { this.accountNo = accountNo; this.overdraft = overdraft; this.accountBalance = accountBalance; accountBalance = 0; } static Account readAccount { int accountNo = In.readInt(); double overdraft = In.readDouble(); if(In.done()) return new Account(accountNo,overdraft); else return null; } void print() { Out.format("%-15d %-15f", accountNo,overdraft); } boolean deposit(double amount) { double amount; Out.print("How much would you like to deposit:"); amount = In.readDouble(); if(amount>0) { return accountBalance = accountBalance+amount; else return null; } boolean withdraw(double amount) { double amount; Out.print("How much would you like to withdraw:"); amount = In.readDouble(); if(accountBalance>=amount) { return accountBalance = accountBalance-amount; else return null; } boolean isCovered(double amount) { double amount; amount = In.readDouble(); if(accountBalance>=amount) return accountBalance; else return null; } boolean transfer(targetAccount,double amount); double amount; Out.println("How much would you like to transfer:"); amount = In.readDouble(); int targetAccount; Out.println("To whom would you like to transfer:"); if(amount<=0 && accountBalance==0) { return null; else return targetAccount = amount; } class Banking { static final int CAPACITY = 100; Account[] accounts = new Account[CAPACITY]; int nOfaccounts; int createAccount(String firstName, String lastName, String phone, double overdraft) { Out.println("Enter your first name:"); String firstName = In.readLine(); Out.println("Enter your last name:"); String lastName = In.readLine(); Out.println("Enter your phone number:"); String phone = In.readLine(); Out.println("Enter the value of overdraft:"); double overdraft = In.readDouble(); if (nOfaccounts == accounts.length) { return -1; } else return boolean deposit(int accountNo,double amount) {
So my question is, why do i need to write in both the account and in banking class the methods deposit withdraw and so on... And also how do i return values with these boolean methods, when i try return(true) or false , when i compile it i get an error.Could anyone help?