problem 1 bank. manage customers’ bank account using the following operations: create a new...
TRANSCRIPT
Problem 1Bank
Manage customers’ bank account using the following operations:
• Create a new account given a customer’s name and initial account.
• Deposit money to a customer’s account.
• Withdraw money from a customer’s account and report whether the transaction is successful or not.
Problem 1 : Bank
Class BankAccountAttributes:
1. private double balance;2. private String name;
Problem 1 : Bank
BankAccount
- balance : double- name : String
Some UML notations…
Problem 1 : Bank
className
- attributeName : Type
- methodName(input) : returnType
Signs
+ : public
- : private
~ : package-level (default)
# : protected
Class BankAccountConstructor
public BankAccount (double balance, String name)
Methods
public void deposit (double amount)
public double withdraw (double amount)
public double getBalance()
Problem 1 : Bank
Deposits <amount> to the corresponding bank account
Withdraws <amount> to the corresponding bank account
Returns the current balance of the corresponding account
BankAccount
- balance : double- name : String
+ depost(double) : void+ withdraw(double) : double+ getBalance() : double
Problem 1 : Bank
Input: Process until “0” is read.
Problem 1 : Bank
while (!operation.equals(“0”)) { //Process the input operation = sc.next();}
//print the final balance of all customers
Problem 2Social Network
Social Network 1
Person name: string ArrayList<Integer> group // the group ids of the
person’s groupsGroup
name: string id: int ArrayList<Person> members
SocialNetwork ArrayList<Person> persons ArrayList<Group> groups. Methods to process queries.
Problem 2 : Social Network
Tasks
For all operations, find the person in the person list. Create a new person object if the person has not been mentioned before.
Createjoin First, check whether the group name already exist. If
not exist, create a new group with the assigned name. Add the person into the group.
Quit Find the person in the member list of the group and
remove it Find the group in the person’s group list, and remove
it.Problem 2 : Social
Network
Tasks
Query 1 Just go through the group list to find the one with
maximum member.size()Query 2
Go through every person x in the person list Counting the number of x’s acquaintances by going
through every person y in the person list Check whether x knows y by going through x’s and y’s
group list. If they are in some same group (if their group lists have some common elements), then they know each other.
Update the person who has the maximum number of acquaintances.
Problem 2 : Social Network
Problem 3Lecturer
Create all the get() and set() methods for the attributes in each class (Lecturer and Office)
Have ArrayList<Office> and ArrayList<Lecturer> in main.
Checklist
Main
Lecturer
Office
Problem 3 : Lecturer
Query 1 : Toggle The Status of a Lecturer
public void toggle() {
}
lecturer.toggle();Main
Lecturer
Problem 3 : Lecturer
this.isActive = !this.isActive;
Query 2 : Allocate an Office to A Lecturer
Mainoffice.addLecturer(lecturer);
public void addLecturer(Lecturer lecturer) {lecturers.add(lecturer);
}
Office
Problem 3 : Lecturer
http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html
Query 3 : Print the Name of An Office that A Lecturer is Allocated
public Office getOffice() {//method one (lazy):
//method two:
}
Lecturer
Sort and take the first element of the list
Loop through each office in the list, take the smallest lexicographically
Problem 3 : Lecturer
Can I just return String instead of Office?
public String getOfficeName() { //operations here return office.getName();}
CAN
Query 4 : Print the Name of An Office that Has the Most Number of Active
Lecturers
public int countActiveLecturers() {
}
Office
for every lecturer in lecturers :if lecturer is active count++
return count
Main
max = 0For every office in offices :
Get number of active lecturers and compare to max
Problem 3 : Lecturer