SlideShare a Scribd company logo
Workshop 2
Q1. Write java program to manage fractions with addition, subtraction, multiplication and
division.
Q2. Vehicle Management System, including: car, motorbike, truck. Each of the Vehicle has
attributes of manufacturer, manufacture year, cost, color. Moreover, cars have types of engine,
number of seats. Motorbikes have power and trucks have load.
Code a class named Car, Motor, Truck are directly derived from base class Vehicle object.
Write a program with the following functions:
1. Input data of vehicles (validation data if necessarily)
2. To view the details of the vehicles (3 vehicles in one table or one for each table), to count
the number of vehicles in the following table.
3. Searching by manufacturer, manufacture year, cost, color, types of engine, seats, …
(exactly or approximately)
4. Searching from .. to…( manufacture year, cost)
5. Sorting by manufacturer, manufacture year, cost, color, types of engine, seats, …
6. To calculate statistics
Q3.
Library Management, including Book, Magazine, Newspaper. Each of the Document has
attributes of code, publisher and circulation (tổng số phát hành). Moreover, Books have author, title
and the number of pages. Magazines have issue number, monthly release. Newspapers have
Release date.
Code a class named Book, Magazine, Newspaper are directly derived from base class
Document object.
Write a program with the following functions:
1. Input data of documents (validation data if necessarily)
2. To view the details of all of documents (3 documents in one table or one for each table),
to count the number of documents in the following table.
3. Remove, update for a document (enter a code of document)
4. Searching by code, publisher, circulation, author, title and the number of pages … (exactly
or approximately)
5. Searching from .. to…( circulation, the number of pages, monthly release, Release date)
6. Sorting by code, publisher, circulation, author, title and the number of pages …
7. To calculate statistics
Q4.
One IT center requies full-time and part-time teachers. Full-time teacher information has teacher
code, full name, email, Professor (Học hàm) (non, Prof. (Professor), Assoc. Prof. (Asscociate
Professor), Assist. Prof. (Assistant Professor)), University degree (học vị) (Bachelor, Master,
Post Doctor), address, phone, number of teaching hours per month, basic pay (lương cơ bản), pay
rate (hệ số lương) (Bachelor: 1, Master: 1.1, Post Doctor: 1.2 and Prof. : +0.3, Assoc. Prof. +0.2,
Assist. Prof. +0.1), Norm hour (số giờ định mức), overtime hour (50.000 vnd/1h).
Part-time teacher information has teacher code, full name, email, Professor (non, Prof.
(Professor), Assoc. Prof. (Asscociate Professor), Assist. Prof. (Assistant Professor)), University
degree (Bachelor, Master, Post Doctor), address, phone, number of teaching hours per month,
pay rate (Bachelor: 1, Master: 1.1, Post Doctor: 1.2 and Prof. : +0.3, Assoc. Prof. +0.2, Assist.
Prof. +0.1), office, (200.000 vnd/1h).
Write a program with the following functions:
1. Enter the information for full-time and part-time teacher (validation data if necessarily)
2. Display all teacher information (in one table or one for each table), to count the number
of teachers in the following table.
3. Remove, update a teacher (enter code of teacher)
4. Searching by code, full name, email, Professor, Assoc. Prof., University degree, address,
phone, number of teaching hours per month, basic pay, pay rate … (exactly or
approximately)
5. Searching from .. to…( number of teaching hours per month, pay rate, …)
6. Sorting by code, full name, email, Professor, Assoc. Prof., University degree, address,
phone, number of teaching hours per month, basic pay, pay rate …
7. To calculate statistics
Q5. We have the design for Phone number:
PhoneNumber
- int area
- String number
+ PhoneNumber()
+ PhoneNumber(int a, String n);
+ void display();
IntPhoneNumber
- String countryCode
+ IntPhoneNumber ()
+IntPhoneNumber (String cc, int a, String n);
+ void display();
Implement the above classes and make your own main program to test all the above
methods. The output of your program something look like:
Enter list of phone numbers
-----------------------------------------
Type of phone number ? (1 – local phone, 2 – Inter phone number,
0 - exit): 1
Enter area code: 111
Enter number: 111111
Type of phone number ? (1 – local phone, 2 – Inter phone number,
0 - exit): 2
Enter country code: 22
Enter area code: 222
Enter number: 222222
Type of phone number ? (1 – local phone, 2 – Inter phone number,
0 - exit): 1
Enter area code: 333
Enter number: 333333
Type of phone number ? (1 – local phone, 2 – Inter phone number,
0 - exit): 2
Enter country code: 44
Enter area code: 444
Enter number: 444444
Type of phone number ? (1 – local phone, 2 – Inter phone number,
0 - exit): 0
List of phone number:
----------------------------------------
111 – 111111
22 – 222 – 222222
333 – 333333
44 - 444 – 444444
Note: You can using an array of base class PhoneNumber object
PhoneNumber phonelist[] = new PhoneNumber[1000]; or
ArrayList< PhoneNumber > phonelist = new ArrayList< PhoneNumber >();
Q6. We have the design for Staff:
Person
- String name
+ Person()
+ Person(String n)
+ void display();
+ double getSalary();
Officer
- double bSalary
+ Officer ()
+Officer (String n, double s)
+ void display();
+ double getSalary();
- Person. getSalary() is an abstract method
- Worker and Officer are subclasses of Person and Worker.salary = hrs * rate
Implement the above classes and make your own main program to test all the above methods
Add the below code to your main function and run
Q7. Create a class named DictionaryWord as:
DictionaryWord
- word: String
- meanings: String
+ DictionaryWord (String word, String meanings)
+ getWord(): String
+ setWord (String word): void
+ getMeanings(): String
+ setMeanings(String meanings): void
Write a program with the following requirements:
Creates 8 DictionaryWord objects with:
● Word and meanings as the table:
Word Meanings
bank robber Steals money from a bank
Burglar Breaks into a home to steal things
Worker
- double hrs
- final double RATE = 5.5
+ Worker()
+Worker(String n, double hrs)
+ void display();
+ double getSalary();
Forger Makes an illegal copy of something
Hacker Breaks into a computer system
Hijacker Takes control of an airplane
Kidnapper Holds someone for ransom money
Mugger Attacks and steals money from someone
Murderer Kills another person
● Ensure that there is no duplicate DictionaryWord objects (02 DictionaryWord objects a
and b are equal when a.word=b.word).
Displays all DictionaryWord in ascending order of word with the format as:
<<no>.<<word>>
<<meanings>>
<<no>.<<word>>
<<meanings>>
Where: <<no>>=1,2…
Hint:
● class DictionaryWord implements Comparable to order 2 DictionaryWord objects.
● override equals(..) method to compare 2 DictionaryWord objects.
● override toString()
● use Set to ensure no duplicate.
● use support class Collections to sort DictionaryWord objects.
Q8 :
1. Create a class Student includes name, age, mark and necessary methods. Using
FileWriter, FileReader and BufferedReader to write a program that has functional menu:
Menu
-------------------------------------------------
1. Add a list of Students and save to File
2. Loading list of Students from a File
3. Exit
Your choice: _
+ Save to File: input information of several students and write that information into a text file,
each student in a line (use tabs to separate the fields)
+ Read File: read and display information of students
Accept a file name from users and display the content of entered file. Display the error
message if that file does not exists.

More Related Content

PDF
Exercise1 java
PPTX
Python programming lab3 250215
PPTX
Lecture 1: basic syntax
PDF
ARRAYS
DOCX
Assignment java workshop
PDF
Lecture 7
PPTX
Programming in c Arrays
PPT
C programming , array 2020
Exercise1 java
Python programming lab3 250215
Lecture 1: basic syntax
ARRAYS
Assignment java workshop
Lecture 7
Programming in c Arrays
C programming , array 2020

What's hot (18)

PDF
DF1 - Py - Ovcharenko - Theano Tutorial
PPTX
Two dimensional arrays
PDF
Arrays and library functions
PDF
8th alg -l8.1
PDF
Arrays in C
PPTX
Arrays and Lists in C#, Java, Python and JavaScript
PPT
Thesis PPT
PDF
Two dimensional array
PPT
Two dimensional array
DOCX
Paper no. 4
PDF
Write a complete C++ program that does the following: 1. The program will c...
PDF
CP Handout#10
PDF
Array
PPS
C programming session 04
PPTX
Whiteboarding Coding Challenges in Python
PPSX
C Programming : Arrays
DF1 - Py - Ovcharenko - Theano Tutorial
Two dimensional arrays
Arrays and library functions
8th alg -l8.1
Arrays in C
Arrays and Lists in C#, Java, Python and JavaScript
Thesis PPT
Two dimensional array
Two dimensional array
Paper no. 4
Write a complete C++ program that does the following: 1. The program will c...
CP Handout#10
Array
C programming session 04
Whiteboarding Coding Challenges in Python
C Programming : Arrays
Ad

Similar to Exercise2 java (20)

PDF
Computer Practical
DOC
Sp 1418794917
PDF
CS Sample Paper 1
 
PDF
Computer Science Sample Paper 2015
PDF
90 Informatics Practices.pdf
PDF
Computer Science Sample Paper 2
 
PDF
computer science sample papers 2
PDF
EEE 3rd year oops cat 3 ans
PDF
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
PDF
Cs practical file
PDF
Ch 4
RTF
CBSE Grade12, Computer Science, Sample Question Paper
DOCX
JAVA practical Exam Questions (1).docx
DOCX
Student DATABASE MANAGeMEnT SysTEm
PDF
Assignment Java Programming 2
PDF
OOP Assignment 03.pdf
DOCX
OOP program questions with answers
PDF
IP Sample paper 2 Class XI
DOCX
Cs pritical file
PPT
Java cơ bản java co ban
Computer Practical
Sp 1418794917
CS Sample Paper 1
 
Computer Science Sample Paper 2015
90 Informatics Practices.pdf
Computer Science Sample Paper 2
 
computer science sample papers 2
EEE 3rd year oops cat 3 ans
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
Cs practical file
Ch 4
CBSE Grade12, Computer Science, Sample Question Paper
JAVA practical Exam Questions (1).docx
Student DATABASE MANAGeMEnT SysTEm
Assignment Java Programming 2
OOP Assignment 03.pdf
OOP program questions with answers
IP Sample paper 2 Class XI
Cs pritical file
Java cơ bản java co ban
Ad

More from NguynMinh294 (20)

PPTX
Slide An toàn mạng nâng cao PTIT
PDF
Phân tích thiết kế hệ thống thông tin PTIT
PDF
Bài giảng mật mã học cơ sở PTIT
PDF
Bài giảng an toàn ứng dụng web và csdl PTIT
PDF
Bài giảng an toàn ứng dụng web và csdl PTIT
PDF
Bài giảng kiểm thử xâm nhập PTIT
PDF
Bài giảng ký thuật theo dõi giám sát mạng PTIT
PDF
Giáo trình mạng máy tính PTIT
PDF
Ktvxl chuong 5 - cac phuong phap vao ra du lieu
PDF
Ktvxl chuong 4 - phoi ghep
PDF
Ktvxl chuong 3 - hop ngu 8088
PDF
Ktvxl chuong 2 - 8086-8088
PDF
Ktvxl chuong 1 - tong quan
PDF
bài giảng ký thuật vi xử lý PTIT
PDF
đề thi java ptit
PDF
Java exercises part 2
PDF
Java exercises part 1
PDF
Bai tap3 java
PDF
Bai tap2 java
PDF
Giáo trình hệ điều hành PTIT
Slide An toàn mạng nâng cao PTIT
Phân tích thiết kế hệ thống thông tin PTIT
Bài giảng mật mã học cơ sở PTIT
Bài giảng an toàn ứng dụng web và csdl PTIT
Bài giảng an toàn ứng dụng web và csdl PTIT
Bài giảng kiểm thử xâm nhập PTIT
Bài giảng ký thuật theo dõi giám sát mạng PTIT
Giáo trình mạng máy tính PTIT
Ktvxl chuong 5 - cac phuong phap vao ra du lieu
Ktvxl chuong 4 - phoi ghep
Ktvxl chuong 3 - hop ngu 8088
Ktvxl chuong 2 - 8086-8088
Ktvxl chuong 1 - tong quan
bài giảng ký thuật vi xử lý PTIT
đề thi java ptit
Java exercises part 2
Java exercises part 1
Bai tap3 java
Bai tap2 java
Giáo trình hệ điều hành PTIT

Recently uploaded (20)

PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Classroom Observation Tools for Teachers
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Presentation on HIE in infants and its manifestations
PPTX
Cell Types and Its function , kingdom of life
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Cell Structure & Organelles in detailed.
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Institutional Correction lecture only . . .
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
VCE English Exam - Section C Student Revision Booklet
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Module 4: Burden of Disease Tutorial Slides S2 2025
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Classroom Observation Tools for Teachers
Final Presentation General Medicine 03-08-2024.pptx
Presentation on HIE in infants and its manifestations
Cell Types and Its function , kingdom of life
O5-L3 Freight Transport Ops (International) V1.pdf
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
GDM (1) (1).pptx small presentation for students
Microbial disease of the cardiovascular and lymphatic systems
Cell Structure & Organelles in detailed.
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Institutional Correction lecture only . . .
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
VCE English Exam - Section C Student Revision Booklet

Exercise2 java

  • 1. Workshop 2 Q1. Write java program to manage fractions with addition, subtraction, multiplication and division. Q2. Vehicle Management System, including: car, motorbike, truck. Each of the Vehicle has attributes of manufacturer, manufacture year, cost, color. Moreover, cars have types of engine, number of seats. Motorbikes have power and trucks have load. Code a class named Car, Motor, Truck are directly derived from base class Vehicle object. Write a program with the following functions: 1. Input data of vehicles (validation data if necessarily) 2. To view the details of the vehicles (3 vehicles in one table or one for each table), to count the number of vehicles in the following table. 3. Searching by manufacturer, manufacture year, cost, color, types of engine, seats, … (exactly or approximately) 4. Searching from .. to…( manufacture year, cost) 5. Sorting by manufacturer, manufacture year, cost, color, types of engine, seats, … 6. To calculate statistics Q3. Library Management, including Book, Magazine, Newspaper. Each of the Document has attributes of code, publisher and circulation (tổng số phát hành). Moreover, Books have author, title and the number of pages. Magazines have issue number, monthly release. Newspapers have Release date. Code a class named Book, Magazine, Newspaper are directly derived from base class Document object. Write a program with the following functions: 1. Input data of documents (validation data if necessarily) 2. To view the details of all of documents (3 documents in one table or one for each table), to count the number of documents in the following table. 3. Remove, update for a document (enter a code of document) 4. Searching by code, publisher, circulation, author, title and the number of pages … (exactly or approximately) 5. Searching from .. to…( circulation, the number of pages, monthly release, Release date) 6. Sorting by code, publisher, circulation, author, title and the number of pages … 7. To calculate statistics Q4.
  • 2. One IT center requies full-time and part-time teachers. Full-time teacher information has teacher code, full name, email, Professor (Học hàm) (non, Prof. (Professor), Assoc. Prof. (Asscociate Professor), Assist. Prof. (Assistant Professor)), University degree (học vị) (Bachelor, Master, Post Doctor), address, phone, number of teaching hours per month, basic pay (lương cơ bản), pay rate (hệ số lương) (Bachelor: 1, Master: 1.1, Post Doctor: 1.2 and Prof. : +0.3, Assoc. Prof. +0.2, Assist. Prof. +0.1), Norm hour (số giờ định mức), overtime hour (50.000 vnd/1h). Part-time teacher information has teacher code, full name, email, Professor (non, Prof. (Professor), Assoc. Prof. (Asscociate Professor), Assist. Prof. (Assistant Professor)), University degree (Bachelor, Master, Post Doctor), address, phone, number of teaching hours per month, pay rate (Bachelor: 1, Master: 1.1, Post Doctor: 1.2 and Prof. : +0.3, Assoc. Prof. +0.2, Assist. Prof. +0.1), office, (200.000 vnd/1h). Write a program with the following functions: 1. Enter the information for full-time and part-time teacher (validation data if necessarily) 2. Display all teacher information (in one table or one for each table), to count the number of teachers in the following table. 3. Remove, update a teacher (enter code of teacher) 4. Searching by code, full name, email, Professor, Assoc. Prof., University degree, address, phone, number of teaching hours per month, basic pay, pay rate … (exactly or approximately) 5. Searching from .. to…( number of teaching hours per month, pay rate, …) 6. Sorting by code, full name, email, Professor, Assoc. Prof., University degree, address, phone, number of teaching hours per month, basic pay, pay rate … 7. To calculate statistics Q5. We have the design for Phone number: PhoneNumber - int area - String number + PhoneNumber() + PhoneNumber(int a, String n); + void display(); IntPhoneNumber - String countryCode
  • 3. + IntPhoneNumber () +IntPhoneNumber (String cc, int a, String n); + void display(); Implement the above classes and make your own main program to test all the above methods. The output of your program something look like: Enter list of phone numbers ----------------------------------------- Type of phone number ? (1 – local phone, 2 – Inter phone number, 0 - exit): 1 Enter area code: 111 Enter number: 111111 Type of phone number ? (1 – local phone, 2 – Inter phone number, 0 - exit): 2 Enter country code: 22 Enter area code: 222 Enter number: 222222 Type of phone number ? (1 – local phone, 2 – Inter phone number, 0 - exit): 1 Enter area code: 333 Enter number: 333333 Type of phone number ? (1 – local phone, 2 – Inter phone number, 0 - exit): 2 Enter country code: 44 Enter area code: 444 Enter number: 444444 Type of phone number ? (1 – local phone, 2 – Inter phone number, 0 - exit): 0 List of phone number: ---------------------------------------- 111 – 111111 22 – 222 – 222222 333 – 333333 44 - 444 – 444444 Note: You can using an array of base class PhoneNumber object
  • 4. PhoneNumber phonelist[] = new PhoneNumber[1000]; or ArrayList< PhoneNumber > phonelist = new ArrayList< PhoneNumber >(); Q6. We have the design for Staff:
  • 5. Person - String name + Person() + Person(String n) + void display(); + double getSalary(); Officer - double bSalary + Officer () +Officer (String n, double s) + void display(); + double getSalary(); - Person. getSalary() is an abstract method - Worker and Officer are subclasses of Person and Worker.salary = hrs * rate Implement the above classes and make your own main program to test all the above methods Add the below code to your main function and run Q7. Create a class named DictionaryWord as: DictionaryWord - word: String - meanings: String + DictionaryWord (String word, String meanings) + getWord(): String + setWord (String word): void + getMeanings(): String + setMeanings(String meanings): void Write a program with the following requirements: Creates 8 DictionaryWord objects with: ● Word and meanings as the table: Word Meanings bank robber Steals money from a bank Burglar Breaks into a home to steal things Worker - double hrs - final double RATE = 5.5 + Worker() +Worker(String n, double hrs) + void display(); + double getSalary();
  • 6. Forger Makes an illegal copy of something Hacker Breaks into a computer system Hijacker Takes control of an airplane Kidnapper Holds someone for ransom money Mugger Attacks and steals money from someone Murderer Kills another person ● Ensure that there is no duplicate DictionaryWord objects (02 DictionaryWord objects a and b are equal when a.word=b.word). Displays all DictionaryWord in ascending order of word with the format as: <<no>.<<word>> <<meanings>> <<no>.<<word>> <<meanings>> Where: <<no>>=1,2… Hint: ● class DictionaryWord implements Comparable to order 2 DictionaryWord objects. ● override equals(..) method to compare 2 DictionaryWord objects. ● override toString() ● use Set to ensure no duplicate. ● use support class Collections to sort DictionaryWord objects. Q8 : 1. Create a class Student includes name, age, mark and necessary methods. Using FileWriter, FileReader and BufferedReader to write a program that has functional menu: Menu ------------------------------------------------- 1. Add a list of Students and save to File 2. Loading list of Students from a File 3. Exit Your choice: _
  • 7. + Save to File: input information of several students and write that information into a text file, each student in a line (use tabs to separate the fields) + Read File: read and display information of students Accept a file name from users and display the content of entered file. Display the error message if that file does not exists.