0% found this document useful (0 votes)
23 views

Ex 5

The document outlines 4 programming questions to create classes for windows, editors, a list to store them, and a tester class. It also includes requirements like using Java 1.8 and formatting test cases. Classes include Window, Editor, MyList, and Tester with methods like add(), search(), and output(). A second question involves a Service class and interface for VAT calculation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Ex 5

The document outlines 4 programming questions to create classes for windows, editors, a list to store them, and a tester class. It also includes requirements like using Java 1.8 and formatting test cases. Classes include Window, Editor, MyList, and Tester with methods like add(), search(), and output(). A second question involves a Service class and interface for VAT calculation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

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”.

Create a package “A”. It includes:

1. Class Window. It has:


- Some fields: width, length (validate: 10<=width<=100, validate: 10<=length<=100)
- Some methods:
+ default constructor: set width=10, length=10
+ The constructor with parameters
+ getters, setters
+ Input()
+ output(): display detail of window
2. An interface “IList”. It has:
- boolean Add(window x)
- Window search(String id)
- void printAll()
- void displayEditors()

Create a package “B”. It contains:

1. Class Editor that extends the class window. It extends some fields and methods
- String id , String title (formatted ID: Exxx , x is digit; formatted title is not empty)
- Constructors, getters, setters, input(),output to display detail of editor
2. Class MyList implements IList
- Some fileds: window [] list , int count
- Implements all methods in IList

Create a package “C”. It contains class “Tester” to test the program

In this class, you have the main method with code like the following:
public static void main(String args[]){
MyList list =new MyList();
Window w=new Window(5,20);
list.add(w);
w=new Window(10,30);
list.add(w);
w=new Editor(E111,”excel”,10,30);
list.add(w);
w=new Editor(E123,”office”,12,24);
list.add(w);
System.out.println(“1.search by id”);
System.out.println(“2.displayAll”);
System.out.println(“3.displayEditors”);
System.out.println(“enter option:”);
Scanner s=new Scanner(System.in);
int c=s.nextInt();
switch(c){

case 1:
System.out.print(“enter id:”);
String id=s.nextLine();
Window result=list.search(id);
if(result!=null){

System.out.println(“OUTPUT:”);
result.output();

}
break;

case 2:
System.out.println(“OUTPUT:”);
list.displayAll();
break;

case 3:
System.out.println(“OUTPUT:”);
list.displayEditors();
break;

(Use try… catch to manage all exceptions and formatted Criteria)


TC1:
INPUT:
enter option:1
enter id:E123
OUTPUT:
E123,”office”,12,24
TC2:
INPUT:
enter option:1
enter id:E223
OUTPUT:
not found
TC3:
INPUT:
enter option:2
OUTPUT:
(5,20)(10,30)(E111,excel,10,30)(E123,office,12,24)
TC4:
INPUT:
enter option:3
OUTPUT:
(E111,excel,10,30)(E123,office,12,24)

Q2: create a new project named “Q2”.

Write a class Service in the default package with the following information:

Service Where:
-name:String  Service(): default constructor, assign values “nail”,
-price:int 200 to all fields
 input(): using the Scanner class to enter all fields
+ Service () from the keyboard
+ input():void  getPrice(): return the price field
+ getPrice(): int  toString(): return the string with format: name-
+ toString():String, override price
for example: nail-200

Write an interface IVAT in the default package with the following information:
<<interface>>
IVAT
+ VAT: int /* assign VAT=10 as default*/
+ getTotalMoneyBeforeVAT(): int, abstract
+ getPaidMoneyAfterVAT(): double, abstract

Write a class Customer that implements the interface IVAT (you can add other functions in Customer
class if need):

Customer Where:
-name:String  usedServices: tracking services is used of the customer.
-usedServices: ArrayList<Service> lists name: the customer’s name
 Customer(name:String): assign the given parameter to
the name field and allocate the memory for the
+ Customer(name:String) usedServices fields
+ addService (Service s): void
 addService(s: Service): add the given parameter to the
+ output():void
usedServices field.
 output(): display information of the customer with
format:
Customer name:Tester
Used Services:

nail-50
spa-50
Total money before VAT: 100

Paid money after VAT:110.0

 getTotalMoneyBeforeVAT(): to return the total money of the usedServices field.


 getPaidMoneyAfterVAT(): to return the paid money after calculating VAT.
paid money= total money before VAT + total money before VAT * (VAT/100)
When running, sample output might look something like :

Enter customer name:tester Enter customer name:tester


Enter the number of used services(n>0):1
Enter the number of used services(n>0):2 Enter service name:facal
Enter service price:150
Enter service name:nail OUTPUT:
Customer name:tester
Enter service price:50 Used Services:
facal-150
Enter service name:spa Total money before VAT:150
Paid money after VAT:165.0
Enter service price:50

OUTPUT:

Customer name:tester

Used Services:

nail-50

spa-50

Total money before VAT:100

Paid money after VAT:110.0

You might also like