Presentation is loading. Please wait.

Presentation is loading. Please wait.

Problem 1 Bank.  Manage customers’ bank account using the following operations: Create a new account given a customer’s name and initial account. Deposit.

Similar presentations


Presentation on theme: "Problem 1 Bank.  Manage customers’ bank account using the following operations: Create a new account given a customer’s name and initial account. Deposit."— Presentation transcript:

1 Problem 1 Bank

2  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

3  Class BankAccount Attributes: 1.private double balance; 2.private String name; Problem 1 : Bank BankAccount -balance : double -name : String

4  Some UML notations… Problem 1 : Bank className -attributeName : Type -methodName(input) : returnType Signs + : public - : private ~ : package-level (default) # : protected

5  Class BankAccount Constructor public BankAccount (double balance, String name) Methods public void deposit (double amount) public double withdraw (double amount) public double getBalance() Problem 1 : Bank Deposits to the corresponding bank account Withdraws to the corresponding bank account Returns the current balance of the corresponding account

6 BankAccount -balance : double -name : String +depost(double) : void +withdraw(double) : double +getBalance() : double Problem 1 : Bank

7  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

8 Problem 2 Social Network

9 Social Network 1 Person  name: string  ArrayList group // the group ids of the person’s groups Group  name: string  id: int  ArrayList members SocialNetwork  ArrayList persons  ArrayList groups.  Methods to process queries. Problem 2 : Social Network

10 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

11 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

12 Problem 3 Lecturer

13 Create all the get() and set() methods for the attributes in each class (Lecturer and Office) Have ArrayList and ArrayList in main. Checklist Main Lecturer Office Problem 3 : Lecturer

14 Query 1 : Toggle The Status of a Lecturer public void toggle() { } lecturer.toggle(); Main Lecturer Problem 3 : Lecturer this.isActive = !this.isActive;

15 Query 2 : Allocate an Office to A Lecturer Main office.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

16 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

17 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 = 0 For every office in offices : Get number of active lecturers and compare to max Problem 3 : Lecturer


Download ppt "Problem 1 Bank.  Manage customers’ bank account using the following operations: Create a new account given a customer’s name and initial account. Deposit."

Similar presentations


Ads by Google