• Tidak ada hasil yang ditemukan

Computer Programming II_ Polymorphism Lab

N/A
N/A
Protected

Academic year: 2025

Membagikan "Computer Programming II_ Polymorphism Lab"

Copied!
3
0
0

Teks penuh

(1)

King Saud University

College of Computer and Information Sciences Department of Computer Science

CSC113 – Computer Programming II_ Polymorphism Lab

1

+Restaurant(in name : String, in location : String, in contact : String, in size : int) +addMenu(in m : Menu)

+selectLunch(in a : double, in time : int) : [ ] Menu +bestLunchOffer() : Menu

-name : String -location : string -contact : String

Restaurant

+Menu(in name : string) +addDish(in d : Dish) : Boolean +display()

+cheapestDish() : Dish +avgDish() : double -name : string

Menu

+Lunch(in name : String, in startTime : int, in buffet : Boolean) +getStartTime() : int

+isBuffet() : Boolean -startTime : int -buffet : Boolean

Lunch

+Dessert(in name : String, in type : String) +getType() : String

-type : String

Dessert

-arrMenu 1

*

+Dish(in name : String, in price : double) +getPrice() : double

+display() -name : String -price : double

Dish -arrDish

1 20

Dish class:

o Attributes:

name: The name of the Dish.

price: The selling price of the Dish.

o Methods:

Dish(name: string, price: double): constructor

getPrice(): This method returns the price of the Dish.

display(): This method displays the name and the price of the Dish.

(2)

King Saud University

College of Computer and Information Sciences Department of Computer Science

CSC113 – Computer Programming II_ Polymorphism Lab

2 Menu class

o Attributes:

name: The name of the Menu.

o Methods:

Menu(name: string): Constructor.

addDish(d: Dish): This method adds a Dish to the Menu. It returns true if the Dish d is added; false otherwise.

display(): This method displays all the attributes of the Menu (or Lunch or Dessert). It displays also all the Dishes of the Menu.

cheapestDish(): This method returns the Dish having the lowest price.

avgDish(): This method returns the average price of all Dishes in the Menu.

Dessert class:

o Attributes:

type: It indicates the type of the Dessert. E.g. “Ice-cream”, “Fruit”, “Cake”, etc.

o Methods:

Dessert(name: string, type: String): Constructor.

getType(): This method returns the type of the Dessert.

Lunch class:

o Attributes:

startTime: It indicates the time when the Lunch starts.

buffet: It indicates whether the Lunch is a buffet or not.

o Methods:

Lunch(name: string, startTime: int, buffet: boolean): Constructor.

getStartTime(): This method returns the start time of the Lunch.

isBuffet(): This method returns the value of the buffet attribute of the Lunch.

QUESTION: Translate into Java code the class Menu and the class Dessert.

(3)

King Saud University

College of Computer and Information Sciences Department of Computer Science

CSC113 – Computer Programming II_ Polymorphism Lab

3 Let’s consider the same class Menu described in exercise 1.

+Restaurant(in name : String, in location : String, in contact : String, in size : int) +addMenu(in m : Menu)

+selectLunch(in a : double, in time : int) : [ ] Menu +bestLunchOffer() : Menu

-name : String -location : string -contact : String

Restaurant

+Menu(in name : string) +addDish(in d : Dish) : Boolean +display()

+cheapestDish() : Dish +avgDish() : double -name : string

Menu -arrMenu 1

*

Restaurant class:

o Attributes:

name: The name of the Restaurant.

location: The location of the Restaurant.

contact: The contact information of the Restaurant.

o Methods:

Restaurant(name: String, location: String, contact: String, size: int): Constructor.

addMenu(m: Menu): This method adds the Menu m to the Restaurant.

selectLunch(a: double, time: int): This method returns all Lunches which the average Dish price is less than a and starts at time.

bestLunchOffer(): This method returns the Menu containing the cheapest Dish.

QUESTION: Translate into Java code the class Restaurant.

Referensi

Dokumen terkait

Alotaibi College of Computer and Information Sciences, King Saud University, Riyadh, Saudi Arabia Received 30 December 2009; accepted 4 July 2010 Available online 8 December 2010

ةيساردلا جهانملاو ططخلا ةنجل 221 Course Specifications Institution: KING KHALID UNIVERSITY , Abha Date: 24/02/2019 College/Department : COLLEGE OF COMPUTER SCIENCE / DEPARTMENT OF

Falke aDepartment of Computer Engineering, College of Computer and Information Sciences, King Saud University, Riyadh, Saudi Arabia bCenter of Smart Robotics Research, King Saud

H Computer Science, Semester II Lab Exercises BHCS03 – Programming in JAVA Attempt the following questions as part of JAVA Lab class today: 1.. Write a program that will count

H Computer Science, Semester II Lab Exercises BHCS03 – Programming in JAVA Attempt the following questions as part of JAVA Lab class today: 1.. Write a program with which you can

1 Ghadah Ahmed Al-Jarallah Lecturer, Computer Science Education: MSc Computer Science & Information Technology, King Saud University, Riyadh, 2018 BSc Computer Science & Information

Member, Committee of recruitments and promotions Department of Biochemistry, College of Science, Sciences & Medical Studies Department for Women Students, King Saud University,

Research & Teaching Experiences: King Saud University - College of Computer & Information Sciences, Computer Engineering Department August 2013 Assistant Professor Courses Name: