Ex 3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Common requirements:

- Create a new folder that is named with the following format: studentID-studentname-
workshopNumber. The folder contains 4 projects: Q1,Q2,Q3,Q4,….
Example: se18123-nguyenvana-WS01 or SE12123-nguyen van a-WS01
- Use jdk 1.8
- The result must be formated like the given tesstcase
- Submit your result to the LMS page( example : se18123-nguyenvana-WS01.zip)

Q1: Create a new project named “Q1”.

1. Create a class Book. It includes some fields: Code, Title and some methods: constructors,
getter,setter and the method output().
2. Create a class DetectiveBook ( This class is derived/extends from Book class).
It extends some fileds: price,year of publication.
And some methods: constructors, getter, setter and the method outputDetectiveBook()
3. Create a class ScienceBook ( This class is derived from Book class).
It extends some fileds: type, (physical, mathematic, chemistry)
And some methods: constructors, getter,setter and the method outputScienceBook()
4. A class Tester which contains the main method(). When the program runs, it displays a menu:
1. Create and display a Detective Book
2. Create and display a Science Book
TC1:
Enter option: 1
enter code: 123
enter title: han va yeu
enter price: 100
enter year:2000
OUTPUT:
123-han va yeu-100-2000
TC2:
Enter option: 1
enter code: 123
enter title: han va yeu
enter type: physical
OUTPUT:
123-han va yeu-physical

Q2: Create a new project named “Q2 to manage some products

 Electric Products< code, name, make, price, guaranty, voltage, power>

 Ceramic Products < code, name, make, price, type >


 Food Products < code, name, make, price , date, expiredDate >

Yeu cau: ve class diagram + implements

When the program runs look like:

TC1 TC2 TC3:


enter code: 1
enter code: 1 enter code: 1 enter name: testing
enter name: testing enter name: testing enter make: VN
enter make: VN enter make: VN enter price: 100
enter price: 100 enter price: 100 1. Input & output an electric
1. Input & output an electric 1. Input & output an electric product
product product 2. Input & output a ceramic
2. Input & output a ceramic 2. Input & output a ceramic product
product product 3. Input & output a food
3. Input & output a food 3. Input & output a food product
product product
Enter option:3
Enter option:1 Enter option:2 enter date:23/2/2023
enter guaranty:12 enter type:physical enter expired
enter voltage:220 OUTPUT: date:23/2/2024
enter power:1 1-testing-VN-100-physical OUTPUT:
OUTPUT: 1-testing-VN-100-23/2/2023-
1-testing-VN-100-12-220-1 23/2/2024

Q2: Create a new project named “Q2”. Write a class Rectangle, and Square that extends the Rectangle
class(in the default package) with the following information:

Rectangle

- length:int
- width:int

+ Rectangle()

+ Rectangle (length: int, width:int)

+ setLength(length: int):void

+ setWidth(width:int):void

+ getLength():int

+ getWidth():int
Square Where:
 Square (side): assign the given side to two fields (length, width), assign
- unit: String the default value is ’cm’ to the unit field.
+ Square (side: int)  setSquare(side): if the given side is the positive number then assign it to
+ setSquare(side: int):void the length, width fields
+ getPerimeter(): int  getPerimeter(): return the perimeter of the square
+ output(): void  output(): display the content with format :
the side of the square=length(unit)
the perimeter of the square=(length+width)*2(unit)
for example:

the side of the square=5(cm)

the perimeter of the square=20(cm)

The program output might look something like:

Enter the side of the square:5 Enter the side of the square:-1

OUTPUT: OUTPUT:

the side of the square=5(cm) the side of the square=0(cm)

the perimeter of the square=20(cm) the perimeter of the square=0(cm)

You might also like