Lab 4
Lab 4
Lab 4
Lab 4
Student ID = 104491255
Week 4- Lab
Task 4.1
package com.labs.week4;
import java.util.Scanner;
do {
//menu
System.out.println("1. Create Account");
System.out.println("2. Print All Accounts");
System.out.println("3. Deposit");
System.out.println("4. Withdraw");
System.out.println("5. Exit");
switch(choice) {
case 1:
//create account
if(index < 5) {
System.out.println("Enter Account Details");
System.out.println("Enter Account ID");
sc.nextLine(); // clear buffer
String id = sc.nextLine();
System.out.println("Enter Account Type");
String type = sc.nextLine();
System.out.println("Enter Account Balance");
double bal = sc.nextDouble();
case 2:
//printing details
for(Account a:myAccounts) {
if(a != null)
a.printDetails();
}
break;
case 3:
//depositing
System.out.println("Enter account ID to deposit : ");
sc.nextLine(); // clearing buffer
String id = sc.nextLine();
}
}
if(!accountFound)
System.out.println("Invalid account ID");
break;
case 5:
System.exit(0);
break;
}while(true);
}
}
Account class:
package com.labs.week4;
//parameterized constructor
public Account(String accountID, String accountType, double accountBalance) {
super();
this.accountID = accountID;
this.accountType = accountType;
this.accountBalance = accountBalance;
}
return false;
}
}
Account
- AccountID: String
- AccountType: String
- AccountBalance: double
+ Account(AccountID: String,
AccountType: String,
AccountBalance: double)
+ getAccountID(): String
+ getAccountType(): String
+ getAccountBalance(): double
+ setAccountBalance(accountBalance: double): void
+ deposit(amount: double): void
+ withdraw(amount: double): boolean
+ toString(): String
Task 4.2
Code:
Customer class:
package com.labs.week4;
@Override
public String toString() {
return "Customer Details: \n" +
"Customer First Name: " + FirstName + "\n" +
"Last Name: " + LastName + "\n" +
"Address: " + Address+ "\n";
}
}
Customer
- FirstName: String
- LastName: String
- Address: String
+ Customer(firstName: String,
lastName: String,
address: String)
+ getFirstName(): String
+ getLastName(): String
+ getAddress(): String
+ toString(): String
Lab 4_2 class:
package com.labs.week4;
import java.util.Scanner;
// Using the data supplied, create a new Customer object and save it in
the array.
customerObjects[i] = new Customer(firstName, lastName, address);
}
Console: