Top Banner
Problem 1 Bank
17

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

Jan 19, 2016

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Problem 1 Bank.  Manage customers’ bank account using the following operations: Create a new account given a customer’s name and initial account. Deposit.

Problem 1Bank

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

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

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

Class BankAccountAttributes:

1. private double balance;2. private String name;

Problem 1 : Bank

BankAccount

- balance : double- name : String

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

Some UML notations…

Problem 1 : Bank

className

- attributeName : Type

- methodName(input) : returnType

Signs

+ : public

- : private

~ : package-level (default)

# : protected

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

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

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

BankAccount

- balance : double- name : String

+ depost(double) : void+ withdraw(double) : double+ getBalance() : double

Problem 1 : Bank

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

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

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

Problem 2Social Network

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

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

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

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

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

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

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

Problem 3Lecturer

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

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

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

Query 1 : Toggle The Status of a Lecturer

public void toggle() {

}

lecturer.toggle();Main

Lecturer

Problem 3 : Lecturer

this.isActive = !this.isActive;

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

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

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

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

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

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