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

Slides:



Advertisements
Similar presentations
Looking inside classes Fields, Constructors & Methods Week 3.
Advertisements

Class Relationships Part 1: Composition and Association CS 21a: Introduction to Computing I First Semester,
IMPLEMENTING CLASSES Chapter 3. Black Box  Something that magically does its thing!  You know what it does but not how.  You really don’t care how.
Locks (Java 1.5) Only one thread can hold a lock at once –Other threads that try to acquire it block (or become suspended) until lock becomes available.
1 Objects, Classes, and Packages “Static” Classes Introduction to Classes Object Variables and Object References Instantiating Objects Using Methods in.
Inheritance Part I. Lecture Objectives To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass.
I NHERITANCE Chapter 10. I NHERITANCE Mechanism for enhancing existing classes You need to implement a new class You have an existing class that represents.
1 CS 171: Introduction to Computer Science II Review: OO, Inheritance, and Libraries Ymir Vigfusson.
Chapter 3 – Implementing Classes. Chapter Goals To become familiar with the process of implementing classes To be able to implement simple methods To.
1 Classes Object-oriented programming: Model the problem as a collection of objects that have certain attributes and interact with one another and/or the.
Chapter 13 Inheritance. An Introduction to Inheritance Inheritance: extend classes by adding methods and fields (variables) Example: Savings account =
1 Using Classes and Working With Class Interfaces November 20, 2002 CSE103 - Penn State University Prepared by Doug Hogan.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
Chapter 9 – Inheritance Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved.
TA: Nouf Al-Harbi NoufNaief.net :::
Inheritance Part III. Lecture Objectives To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke.
Arrays Horstmann, Chapter 8. arrays Fintan Array of chars For example, a String variable contains an array of characters: An array is a data structure.
Interfaces. Lecture Objectives To learn about interfaces To be able to convert between class and interface references To appreciate how interfaces can.
ECE122 L6: Problem Definition and Implementation February 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation.
Datalogi A 8: 27/10. Array Array: Sequence of values of the same type Construct array: new double[10] Store in variable of type double[] double[] data.
Threads A thread is a program unit that is executed independently of other parts of the program A thread is a program unit that is executed independently.
Chapter 9: Classes with Instance Variables or Classes=Methods+Variables Asserting Java © Rick Mercer.
© The McGraw-Hill Companies, 2006 Chapter 7 Implementing classes.
IEG 3080 Tutorial 6 Jack Chan. Prepared by Jack Chan, Spring 2007 Outline UML Basic Class Diagram Sequence Diagram Examples Assignment 2 General Concept.
Inheritance and Subclasses in Java CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University.
(c) University of Washington04-1 CSC 143 Java Inheritance Example (Review)
Object-Oriented Programming in C++
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
ACO 101: Introduction to Computer Science Anatomy Part 2: Methods.
 Sometimes a new class is a special case of the concept represented by another ◦ A SavingsAccount is-a BankAccount ◦ An Employee is-a Person  Can extend.
CSE 143 Lecture 2 More ArrayList ; classes and objects reading: 10.1; slides created by Marty Stepp and Hélène Martin
Introduction to Java Classes and Objects Bank Account Program.
Inheritance CSC 171 FALL 2004 LECTURE 18. READING Read Horstmann, Chapter 11.
Example 2 Adding Integers Find the sum – CHECK You can use a number line to check your answer –= 8 – Use sign of number with greater absolute.
1 Warm-Up Problem Just like with primitive data types (int, double, etc.), we can create arrays of objects. ex: bankAccount employees[100]; Problem: It’s.
Classes: Member Functions and Implementation November 22, 2002 CSE103 - Penn State University Prepared by Doug Hogan.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
CHAPTER 11 INHERITANCE. CHAPTER GOALS To understand how to inherit and override superclass methods To be able to invoke superclass constructors To learn.
Session 02 and 03: C# OOP 1 OOP in C#: Classes and Objects in C#. Object-Oriented Design. UML Class Diagram. Object Interaction. FEN AK IT:
1 Strings, Classes, and Working With Class Interfaces CMPSC 122 Penn State University Prepared by Doug Hogan.
ACM/JETT Workshop - August 4-5, : Defining Classes in Java.
Class Design I Class Contracts Readings: 2 nd Ed: Section 9.5, Advanced Topic nd Ed: Section 8.5, Advanced Topic 8.2 Some ideas come from: “Practical.
Cinema SIT-IN LAB 2 (JAVA). Problem 1.Chairs in the cinema are arranged in rows 2.Each row has a name, and a capacity 3.Allocate groups of people to the.
Bank Account Example public class BankAccount { private double balance; public static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++;
CSE 143 Lecture 2 More ArrayList ; classes and objects reading: 10.1; slides created by Marty Stepp and Hélène Martin
Inheritance and Subclasses CS 21a. 6/28/2004 Copyright 2004, by the authors of these slides, and Ateneo de Manila University. All rights reserved L16:
 Sometimes a new class is a special case of the concept represented by another ◦ A SavingsAccount is-a BankAccount ◦ An Employee is-a Person  Can extend.
Sit-In Lab 2 - OOP Restaurant.  Manage a restaurant and perform these types of queries: Assign a favorite table to a specific group Assign the lexicographically-smallest.
Jeopardy Print Me Which loop? Call Me Name Me My Mistake Q $100 Q $200 Q $300 Q $400 Q $500 Q $100 Q $200 Q $300 Q $400 Q $500 Final Jeopardy.
Monday, Jan 27, 2003Kate Gregory with material from Deitel and Deitel Week 4 Questions from Last Week Hand in Lab 2 Classes.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 6 Acknowledgement: Contains materials provided by George Koutsogiannakis and Matt Bauer.
©2000, John Wiley & Sons, Inc. Horstmann/Java Essentials, 2/e Chapter 3: An Introduction to Classes 1 Chapter 3 An Introduction to Classes.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
Designing Classes Lab. The object that you brought to class Put it in the basket we will exchange them now.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Lecture 3 John Woodward.
Data Structures and Algorithms revision
Java OOP Overview Classes and Objects, Members and Class Definition, Access Modifier, Encapsulation Java OOP Overview SoftUni Team Technical Trainers.
Lecture Notes – Inheritance (Ch 9-10)
Implementing Classes Yonglei Tao.
Phil Tayco Slide version 1.1 Created Oct 30, 2017
Computing with C# and the .NET Framework
The Basics of Class Diagrams for a single class
Writing Methods AP Computer Science A.
د.سناء الصايغ الفصل الأول البرمجة الشيئية
CS2011 Introduction to Programming I Objects and Classes
Arrays and Array Lists CS 21a.
JAVA CLASSES.
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

Problem 1 Bank

 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 BankAccount Attributes: 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 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

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 2 Social Network

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

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 3 Lecturer

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

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 Main office.addLecturer(lecturer); public void addLecturer(Lecturer lecturer) { lecturers.add(lecturer); } Office Problem 3 : Lecturer

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