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

PRO192

Uploaded by

huyldhe186829
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)
30 views

PRO192

Uploaded by

huyldhe186829
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/ 156

Đề 1- 14

Question 1: (2 Point) Design and code a class named Person that holds information of a
Person.

Person
-name:String
-age:int
+Person ()
+Person(name:String, age:int)
+getName():String
+getAge():int
+setAge(age:int):void
+toString():String

1. getName(): String – return a name of the person where every letters are in uppercase.

2. getAge(): int – return a age of the person

3. setAge(Age:int): void – set current age of the person is to a given age.

4. toString():String – return value of a Person as a string age name

Do not format the result

The program output might look something like:

No of test Correct output


case
1

2
3

Question 2: (3 Point) Design and code a class named Computer that holds information about
a Computer and class named SComputer which is derived from Computer.

 toString():String - return information of a SComputer as a string as format of Name price


color series
 getSalePrice():double – use to determine sale fare of a Computer, sale price = original price –
discount, where:
 discount = 5 percent out of original price if last of series is ‘A’.The
comparison must ignores the case during comparison
 otherwise discount = 1 percent out of original price.
Do not format the format the result.

The program output might look something like:

Correct output Correct output


Question 3: (2 Point)
Design and code a class named Bicyle that holds information about a Bicyle.

The interface IBicycle is given (DO NOT CREATE THIS ONE). Design and code a class named
MyBicycle which will implement interface IBicycle and complete 2 methods which were declared in
IBicycle:
 void f1(List<Bicycle > a) – remove from the list of Bicycle "a" the first Bicycle has chepeast
price
 int f2(List<Bicycle > a, String name) - count and return number of Bicycle which are in the list
“a” and has given name in last of the name. The comparison must ignores the case during
comparison.

Given some data which is added to list “a” in the Main already:

Bicyle name Bicyle price

Yamaha 2017A 110

Audi 2017B 250

Porche 2017C 120

By using given data, the program output might look something like:

Question 4: (3 Point) You are given an interface named House (DO NOT CREATE THIS
ONE). Design a class MyHouse which will implement the interface House.
2. double getPricetoUSD()– used to convert price in VND into USD . Given 1USD = 23000
VND
3. String getCode() – assuming that length of address is greater than 3 ; this function return code of
address as the rule:

 Code of address = first 3 characters of address if address constains digit only.


 Otherwise Code of address = last 3 characters of address.
No of test Correct output
case
1

Đề 2
Question 1:
(2 marks) Read PE instructions at the bottom of the exam paper.
Do not pay attention to real meaning of objects, variables and
their values in the questions below.

Write a class named Book that holds information of a book.


Where:
· Book() - default constructor.
· Book(title:String, price:int) - constructor, which sets
values to title and price.
· getTitle():String - return title in uppercase format.
. getPrice():int - return price.
· setPrice(price:int):void - update price.

Do not format the result.

The program output might look something like:


Question 2:

(3 marks) Write a class named Car that holds information about a


car and class named SpecCar which is derived from Car (i.e. Car
is super class and SpecCar is sub class)
Where:
· getMaker():String - return maker.
· getPrice():int - return price.

· setMaker(maker:String):void - update maker.


. toString():String - return the string of format:
maker, price
Where:
. toString():String - return the string of
format:
maker, price, type
. setData():void - Add string "XZ" to the
head of maker and increase price by 20.
· getValue():int - Return price+inc, where
if type<7 then inc=10, otherwise
inc=15.
Question 3:
Write a class named Car that holds information about a car
Write a class named MyCar, which implements the interface ICar.
The class MyCar implements methods
f1, f2 and f3 in ICar as below (you can add other functions in
MyCar class):

. f1: Return the whole part of average rate of all cars (e.g. the
whole part of 3.7 is 3).
. f2: Find the first max and min rates in the list and swap their
positions.
. f3: Sort the list by maker alphabetically, in case makers are the
same, sort them descendingly by rate.

When running, the program will add some data to the list. Sample
output might look something like:
Question 4:

(2 marks) The interface IString below is already compiled and


given in byte code format, thus you can
use it without creating IString.java file.

Write a class named MyString, which implements the interface


IString. The class MyString implements
methods f1 and f2 in IString as below:
· f1: Count and return number of prime digits in str.
. f2: Reverse order of all words in str (word = a string without
space).

The program output might look something like:

Đề 4

· getCode(): String - return a code of the Brick where every letters


are in uppercase.
. getPrice(): double - return price of the Brick.
· setPrice(price:double): void - set current price of the Brick to a
given price.
Do not format the result

The program output might look something like:

Question 2:

(3 Point) Design and code a class Brick that holds information


about a Brick and class ColorBrick which is derived from Brick.
Where:
1. getPrice():double - return the price of a Brick.
2. getCode():String - return the code of a Brick.
3. toString():String - return information of a Brick as
a string as format of code price

. toString():String - return information of a ColorBrick as a string


as format of code maker price
· getPrice():double - use to determine price of a ColorBrick, price
= original price + increment,
where:
. increment = 10 percent out of original price if maker starts with
"J" or "j".
· otherwise increment = 0.
Do not format the format the result.

The program output might look something like:


Question3:
Design and code a class Brick that holds information about a
Brick
Where:
1. getCode():String - return code of a Brick
2. getPrice():double- return price of a Brick
3. setPrice(price:double):void - set current price to a given
price
4. setCode(code:String):void - set curent code to a given
Code
The interface Ibrick is given (DO NOT EDIT THIS ONE)
Design and code a class MyBrick which will implement interface
IBrick and complete 3 methods which were declared in IBrick:

. Method named f1: increment price by 10 percent out of original


price for all Bricks which are in
the list "list" and have price is less than the largest Brick.
. Method named f2: count and return the number of Bricks in the
list "list" which price is less than
or equals to given price "d".
. Method named f3: remove the second largest Brick price in the
list "list".

Given some data which is added to list "list" in the Main already:
Question 4:
You are given an interface named IString (Do not edit this one)
Design a class MyString which will implement the interface
IString.
1. int sum(string:String) - this function return summation of a
given string "string" as the rule:
sum = sum of all digits of the first and the last numbers in the
given "string".
2. String getCode(string:String) - this function return code of
"string" as the rule:
o Code of string = reverse the first and the last number in the
given string "string" only.
Only one empty space between two words in the result.

The program output might look something like:

Đề 5 -6
Question 1:
Edit: Design and code a class name DessertIterm that holds
information of a DessertIterm
Design and code a deringving class name Candy from
DessertIterm that holds information about Candy
DessertIterm
String Name;
DessertIterm( String
Xname)

Candy
Price doublle;
Weight double ;
Candy( String Xname,
double X;price, double
Xweight)
double getCost()

Constructers to set value for instance variables.


Add needed operations to the class so that the main function can be
run and complete the below method which is declared in Candy class,
the function will be used in second test case
In Candy class: -double getCost()-use to determine its cost,
cost=price*weight, the cost shoude be arounded tho the closest double
value with tie rounding up if Candy name start with letter “C” or”c”,
ortherwisre the cost shoude be a rounded to the closest double value
with ties rounding down
Test Case
Enter dessert name: Whilte Chocolate Fudge
Enter candy price: 1.04
Enter candy weight: 2
Enter TC: 2
OUTPUT:
2.0
Enter dessert name: Chocolate Fudge
Enter candy price: 1.04
Enter candy weight: 2
Enter TC: 2
OUTPUT:
3.0
…………………………………………………
Enter dessert name: Chocolate Fudge
Enter candy price: 1.04
Enter candy weight: 2
Enter TC: 1
OUTPUT:
Chocolate Fudge
Chocolate Fudge 2.0 1.04
Question 2:
Edit:
Iinvoice (interface)-do not edit
+ String f1(ArrayList<invoice a, int st>;
++ int f2(ArrayList<invoice a);

Invoice
MyInvoice

+ String f1(ArrayList<invoice a, int st>


- String Name
+ int f2(ArrayList<invoice at>
- int Total amount; +
-Invoice(String Name, int
Totalamount)
Constructers to set value for instance variables.
String f1(ArrayList<invoice a, int st>-if st=1, firstly, sort the list “a”
of invoices by customer name ( ascending), finally, return customer
name of second invoice in the list “a”. The must ignores the case
during comparison.
if st=2, firstly, sort the list of invoices by total amount
(ascending) , finally, return customer name of second invoice in the
list “a”.
int f2(ArrayList<invoice a> : set x the first highest amount of
invoice and y is the second amount of invoice;remove all invoice
wich have the amount of invoice equals to amount of x and y in the
list “a”, finally caculate and return the sum of amount of all ather
invoice in the list a;
Enter number of Invoice: 4

name to customer: Noi


Total amount: 96

name to customer: Ha
Total amount: 77

name to customer: Mua


Total amount: 96

name to customer: nay


Total amount: 100
Enter test function (1-f1;2-f2): 1
OUTPUT:
ST=1
Mua
Enter number of Invoice: 4

name to customer: Ha
Total amount: 96

name to customer: Noi


Total amount: 77
name to customer: Mua
Total amount: 96
name to customer: nay
Total amount: 100
Enter test function (1-f1;2-f2): 1
OUTPUT:
ST=2
Ha
Enter number of Invoice: 4
Issue to customer: Obama
Total amount: 96
Issue to customer: Putin
Total amount: 77
Issue to customer: Xi Jinping
Total amount: 96
Issue to customer: Trump
Total amount: 100
Enter test function (1-f1;2-f2): 2
OUTPUT:
77
Question 3. Design and code a class named MyCard that holds
information of a payment card, including:
MyCard
String cardNumber;
String type;;
MyCard( String
cardNumber, String
type)
- Constructor to set values for instance variable. Make sure that a
valid payment card number is a string which constains letters
only, reset payment card number to a string of “0000” (4(four)
digits of 0) if payment card number is not valid.
- Add need operations to the class and complete below method
which is declared in MyCard class, the function will be used in
the second tesst case.
+ String getCardCode()- assuming that length of payment
card is greater than 4 this function return value of card
code as the rule:
 Card code= last 4 didits of payment card number
if type of card is “credit”.
 Atherwise card code= firts 4 didits of payment
card number;
TEST CASE
Enter card type: credit
Enter card number: hanoimuanayvangnhungconmua
Enter TC: 2
OUTPUT:
nmua
Enter card type: credit
Enter card number: hanoimuanayvangnhungconmua
Enter TC: 1
OUTPUT:
credit hanoimuanayvangnhungconmua
Enter card type: debit
Enter card number: hanoimuanayvangnhungconmua
Enter TC: 2
OUTPUT:
Hano
Enter card type: debit
Enter card number: hanoi7muanayvangnhungconmua
Enter TC: 1
OUTPUT:
debit 0000

Đề 7
Question 1:
Design and code a class name named Car that holds
information of a Car
· getName[): String - return a name of the Car where every letters are
in uppercase.
. getPrice(): double - return price of the Car.
· setPrice(price:double): void - set current price of the car to a given
price.
Do not format the result

The program output might look something like:


Question 2:
Design and code a class named Tivi that holds information
about a Tivi and class named ColorTivi which is derived
from Tivi
Where:
1. getPrice():double - return the price of a Tivi.
2. getType():String - return the type of a Tivi.
3. toString():String - return information of a Tivi as a
string as format of type price
. toString():String - return information of a ColorTivi as a
string as format of type serie price
· getPrice():double - use to determine price of a Tivi, price
= original price - decrement, where:
· decrement = 10 percent out of original price if Tivi serie
> 3000.
. otherwise decrement = 0.
Do not format the format the result.

The program output might look something like:


Question 3:
Design and code a class Fan that holds information about
a Fan
Where:
1. getCode():String - return code of a Fan
2. getPrice():double- return price of a Fan
3. setPrice(price:double):void - set current
price to a given price
4. setCode(code:String):void - set curent code
to a given code
The interface IFan is given (Do not edit this one)
Design and code a class coded MyFan which will
implement interface IFan and complete 3 methods which
were declared in IFan.

. Method named f1: remove all Fans in the list "a" which
code start with the given code.
. Method named f2: count and return the number of Fan
in the list "a" which price is less than or
equals to given price.
. Method named f3: move all fans which are in the list "a"
and have price is greater than or equals
to given price to beginning of the list (in the same order of
original list), other fans are
unchanged.

Given some data which is added to list "a" in the Main


already:

Question 4:
You are given an interface named IString (Do not edit this
one). Design a class MyString which will implement the
interface IString.

1. int sum(rc:String) - used to calculate the summation of


all even digits in a given string "rc".
2. String getCode(rc:String) - this function return code of
RC as the rule:
o Code of RC = all digit characters and uppercase letters
in the same order as original given
string "rc".
The program output might look something like:
Đề 8
Question 1: (2 Point) Design and code a class named Teacher that holds information of
a Teacher.

Teacher
-name:String
-salary:double
+Teacher ()
+Teacher (name:String,salary:double)
+getName():String
+getSalary():double
+setSalary(salary:double):void
+toString():String
1. getName(): String – return a name of the teacher where every letters are in uppercase.

2. getSalary(): double – return a salary of the teacher

3. setSalary(salary:double): void – set current salary of the teacher is to a given salary.

4. toString():String – return value of a Teacher as a string name salary

Do not format the result

The program output might look something like:

No of test Correct output


case
1

Question 2: (3 Point) Design and code a class named Motor that holds information
about a Motor and class named VNMotor which is derived from Motor.
 toString():String - return information of a VNMotor as a string as format of brandName
series price
 getSalePrice():double – use to determine sale fare of a Motor, sale price = original price –
discount, where:
 discount = 5 percent out of original price if original price < 3000.
 otherwise discount = 10 percent out of original price.
Do not format the format the result.

The program output might look something like:

Correct output Correct output

Question 3: (3 Point)
Design and code a class named Printer that holds information about a Printer.

Printer Where:
-price:double 1. getName():String – return name of a Printer
-name:String 2. getPrice():double– return price of a Printer
+Printer()
+Printer(name:String,price:double)
+getName():String
+getPrice():double

The interface IPrinter is given (DO NOT CREATE THIS ONE). Design and code a class named
MyPrinter which will implement interface IPrinter and complete 2 methods which were declared in
IPrinter:

 void f1(List<Printer> a, double price) – remove from the list of printers "a" all printers which
has price less than or equals to given price.
 int f2(List<Printer> a, String name) - count and return number of printers which are in the list
“a” and has name contains given name. The comparison must ignores the case during
comparison.

Given some data which is added to list “a” in the Main already:

Printer name Printer price

HP 200J 110

HP 2000G 150

Canon G1240 120

By using given data, the program output might look something like:
Question 4 (2 Point) You are given an interface named Convertible (DO NOT
CREATE THIS ONE). Design a class MyConvertible which will implement the interface
Convertible.

1. double toMile(km:double) – used to convert a km value to mile value. Given 1km =


0.621371 mile

2. String getCode(rc:String) – assuming that length of Reservation code is dividable by 3 ; this


function return code of RC as the rule:

 Code of RC = separate a RC into groups, each group has exactly 3 characters with same
order of orginal RC, groups are seperated by character “-“, eg A12-BE2-CM5
The program output might look something like:

No of test Correct output


case
1
2

Đề 9
Question 1:
Write a class food Tern that holds information of a term
Where
 Tern() – default constructor
 Tern(food: String, type:int) – constructor,which sets
values to food and type
 getFood(): String – return food in uppercase format.
 getType(): int – return type
 setType(type: int):void – update type.
Question 2:
Write a class named Vase that holds information about a
vase and class named SpecVase which is derived from Vase
(i.e. Vase is super class and SpecVase is sub class)
Where
 getMaker(): String – return maker
 getType(): int – return type
 toString(): String – return the string of format:
maker type
Where
 getNewType(): int – return the value type+inc,
where if maker starts with “BA” then inc = 20,
otherwise inc=10
 toString(): String – return the string of format:
maker type color
Question 3:
Write a class named Vase that holds information about a
vase
Where:
 getMaker(): String – return maker
 getType():int – return type
 setMaker(maker: String): void – update maker
 setType(type:int):void – update type
The interface IVase below is already compiled and given
in byte code format, thus you can use it without creating
IVase.java file

Write a class named MyVase, which implements the


interface IVase. The class MyVase implements methods
f1, f2 and f3 in IVase as below (you can add other
functions in MyVase class):
. f1: count and return the number of vases with maker
starting with 'B' and ending with 'A'.
· f2: Reverse the first 5 elements in the list (other
elements are unchanged).
· f3: Remove the second element having type > 5.

When running, the program will add some data to the


list. Sample output might look something like:

Question 4:
The interface IString below is already compiled and
given in byte code format, thus you can use it without
creating IString.java file

Write a class named MyString, which implements the


interface IString. The class MyString implements
methods f1 and f2 in IString as below:
. f1: Count and return number of words ending with
digit (word = a string without space(s).
. f2: Return the string by replacing the first shortest
word in str by it's length.

The program output might look something like:


Đề 10
Question 1:

(3 marks) You have main function which is saved on folder named Q1 already. Use these
classes and functions to test all your operations in this question, CAN EDIT ANY CODE in
main function. You can add more operations/classes/interfaces to be able to answer the below
questions.

Design and code a class named Student that holds information about a Student. Information
of a Student includes:
 A string describes the name of a Student.

Include the following member functions in your design:

 Constructors to set values for instance variables.


 Add needed operations to the class.
Design and code a deriving class named GStudent from Student class that holds information
about a Student. Information of a Student includes:
 A whole value holding Grade of a Student.
 A String holding Class name of a Student.
Include the following member functions in your design:

 Constructors to set values for instance variables.


 Add needed operations to the class so that the main function can be run
and complete the below method which is declared in Student class, the
function will be used in second test case.
o int getGrate() – this function return value of Student’s Grate.
The program output might look something like:

Enter Student name: Ha

Enter Student Grade: 6

Enter Student Class: IT

Enter TC: 2

OUTPUT:

Enter Student name: Ha

Enter Student Grade: 6

Enter Student Class: IT

Enter TC: 1

OUTPUT:

Ha

Ha 6 IT

Question 2:

(4 marks) You have main function which is saved on folder named Q2 already. Use these
classes and functions to test all your operations in this question, CAN EDIT ANY CODE in
main. You can add more operations/classes/interfaces to be able to answer the below
questions.
We had provided you:
1. Interface – ICar which will declare some operations on Car – DO NOT EDIT this one.
2. You only need to complete the code in class MyCar and Car.
Design and code a class named Car that holds information about a Car. Information of a Car
includes:
 ID string describing ID of a Car
 A string describing name of a Car.
 An integer value holding price of a Car.
Include the following member functions in your design:
 Constructors to set values for instance variables.
 Add needed Get….()/Set….() to the class.
 Add needed operations to the class so that the main function can be run.
Design and code a class named MyCar which will implement interface ICar and complete 2
methods which were declared in ICar.
 String f1(ArrayList<Car> b) – assume that given list “b” is not empty. Write your java code to
find and return name of last Car in given list “a”.
 String f2(ArrayList<Car> b) – assume that given list “b” is not empty. Write your java code to
find and return name of first Car in given list “a”.

 int f3(ArrayList<Car> a, int price) – Write your java code to find and return the number of Cars
in given list “a” which have price greater than or equals to given “price” (given price as input
parameter).

 Int f4(ArrayList<Car> a) – Write your java code to sort list “a” ascending by name Car
The program output might look something like:

Enter number of Car: 3

Enter Car ID: 2

Enter Car name: For

Enter Car Price: 2000

Enter Car ID: 1

Enter Car name: Kia

Enter Car Price: 1000

Enter Car ID: 3

Enter Car name: Med

Enter Car Price: 4000

Enter counting price: 1

Enter test function (1-f1;2-f2;3-f3;4-f4): 1

OUTPUT:

Med

Enter number of Car: 2

Enter Car ID: 1


Enter Car name: kia

Enter Car Price: 4000

Enter Car ID: 2

Enter Car name: for

Enter Car Price: 5000

Enter counting price: 4000

Enter test function (1-f1;2-f2;3-f3;4-f4): 2

OUTPUT:

Kia

Enter number of Car: 2

Enter Car ID: 1

Enter Car name: for

Enter Car Price: 3000

Enter Car ID: 2

Enter Car name: Med

Enter Car Price: 5000

Enter counting price: 5000

Enter test function (1-f1;2-f2;3-f3;4-f4): 3

OUTPUT:

Enter number of Car: 3

Enter Car ID: 1

Enter Car name: 1

Enter Car Price: 1

Enter Car ID: 3

Enter Car name: 3


Enter Car Price: 3

Enter Car ID: 2

Enter Car name: 2

Enter Car Price: 2

Enter counting price: 2

Enter test function (1-f1;2-f2;3-f3;4-f4): 4

OUTPUT:

[111, 222, 333]

Question 3:

(3 marks) You have main function which is saved on folder named Q3 already. Use these
classes and functions to test all your operations in this question, CAN ANY CODE in main
function. You can add more operations/classes/interfaces to be able to answer the below
question.

Design and code a class named Sudent, that holds information of a Sudent, including:
 A string describes ID of a sudent as the format like “Pro192_01”,

 A string describes name of a sudent as the format like “Phan Thi Ha”,
 A whole number describes age of a sudent.
Include the following member functions in your design:

 Constructors to set values for instance variables.


 Add needed Get….()/Set….() to the class.
 Add needed operations to the class and complete below method which is
declared in Sudent class, the function will be used in second test case.
 String getLastname() – this function return value of Lastname of a name.
 String getLastID() – this function return token last of ID of a ID.

The program output might look something like:

Enter student ID: Pro192_01

Enter student name: Nguyen Thi Minh Anh

Enter student age: 20

Enter TC: 1
OUTPUT:

Pro192_01 Nguyen Thi Minh Anh 20

Enter student ID: Pro_135

Enter student name: Nguyen thi Hai

Enter student age: 20

Enter TC: 2

OUTPUT:

Hai

Enter student ID: Pro_135

Enter student name: Nguyen thi Hai

Enter student age: 30

Enter TC: 3

OUTPUT:

135

Đề 11 – FA 20
Question 1:
Write a class named Balloon that holds information of a
ballon
Where
 Balloon(): default constructor
 Balloon(owner: String, color:int) – constructor, which
sets value to owner and color.
 getOwner(): String – return owner in uppercase
format
 getColor(): int - return color
 setColor(color: int): void – update color

Question2:
Write a class named Beaver that holds information
about a beaver and class named SpecBeaver which is
derived from Beaver( i.e. Beaver is super class and
SpecBeaver is sub class)
Where:
 getRiver(): String – return river
 getFeature(): int – return feature
 setRiver(river: String): void – update river
 toString(): String – return the string of format: river,
feature
Where:
 toString(): String – return the string of format:
river, feature,weight
 setData():void-Increase feature by 15
 getValue():int – check if river contains “YX” then
return feature*3, otherwise return feature*4

Question 3:
Write a class named Beaver that holds information
about a beaver
Where:
 getRiver():String-return river
 getWeight():int-return weight
 setRiver(river:String):void – update river
 setWeight(weight:int):void – update weight

Write a class named MyBeaver, which implements


the interface IBeaver. The class MyBeaver
implements methods f1, f2 and f3 in IBeaver as
below (you can add other functions in MyBeaver
class):

. f1: Count and return number of beavers having


weight>avg, where avg is the average weight of
all beavers (avg is double type).
. f2: Suppose the list contains at least 3 elements.
Remove the first beaver with maximum weight
and insert it to position 2 of the list (position of the
first element is 0).
. f3: Suppose the list contains at least 7 elements.
Sort elements from position 2 to 6 by river
alphabetically (other elements are unchanged), in
case rivers are the same, sort them
descendingly by weight.
Question 4:
The interface IString below is already compiled
and given in byte code format, thus you can use it
without creating IString.java file

Write a class named MyString, which implements


the interface IString. The class MyString
implements methods f1 and f2 in IString as below:

. f1: Count and return number of words containing


at least 3 digits (word = a string without
space(s)).
. f2: Remove the first alphabetically un-sorted word
in the string str (e.g if str="ab bc de hoa ef la
la" then the word hoa is that one).
The program output might look something like:
Đề 11 – sample PE 2
Question 1: (3 marks) You have main function which is saved on
folder named Q1 already. Use these classes and functions to test all your
operations in this question, DO NOT EDIT ANY CODE in main function.
You can add more operations/classes/interfaces to be able to answer the
below question.

Design and code a class named Employee that holds information about a
Employee. Information of an Employee includes:
 A string describes the name of an Employee.
 A double value describes basic salary of an Employee.
Include the following member functions in your design:
 Constructors to set values for instance variables.
 Add needed operations to the class.
Design and code a deriving class named Seller from Employee class
that holds information about a Seller. Information of a Seller
includes:
 A double value describes revenue of a Seller of a year.
Include the following member functions in your design:
 Constructors to set values for instance variables.
 Add needed operations to the class so that the main function can
be run and complete the below method which is declared in Seller
class, the function will be used in second test case.
o double getSalary() – use to determine sale price of a seller;
salary = basic salary + bonus, where:
 bonus = 5 percent out of revenue if revenue < 30000.
 otherwise bonus = 10 percent out of revenue.

The program output might look something like:

No Correct output Correct output


of
test
cas
e
2

1
Question2: (4 Point) You have main function which is saved on folder named Q2
already. Use these classes and function to test all your operations in this question, DO NOT
EDIT ANY CODE in main. You can add more operations/classes/interfaces to be able to
answer the below questions.
We had provided you:
1. Interface – ICourse which will declare some operations for a Course – DO NOT EDIT this
one.
2. You only need to complete the code in class MyCourse and Course.
Design and code a class named Course that holds information about a Course. Information of
a Course includes:
 A double value holding fee of a Course.
 A string describing name of a Course.
Include the following member functions in your design:

 Constructors to set values for instance variables.


 Add needed operations to the class so that the main function can be run and complete the
function
o String getName() – return name of a Course.
Design and code a class named MyCourse which will implement interface ICourse and complete 2
methods which were declared in ICourse

 void f1(List<Course> a, int st) – Sort the list of courses "a" ascending by course fee if st = 1
otherwise sort the list of courses "a" descending by course name. The comparison must
ignores the case during comparison.

 int f2(List<Course> a, double fee) - count and return numbers of courses in the list “a” which
are in the list “a” and has course fee greater than or equals given fee.

Given some data which is added to list “a” in the Main already:

Course name Course fee

PRJ311 110

DBI202 150

PRF192 120

By using given data, the program output might look something like:
Question 3: (3 Point) You have main function which is saved on folder named Q3
already. Use these classes and functions to test all your operations in this question, DO NOT
EDIT ANY CODE in main function. You can add more operations/classes/interfaces to be
able to answer the below question.

Design and code a class named ReservationCode that holds information of a


ReservationCode (RC) for a customer, including:
 A string describes value of a customer name.
 A string describes value for a RC.
Include the following member functions in your design:

 Constructors to set values for instance variables.


 Add needed operations to the class and complete below method which is declared in
ReservationCode class, the function will be used in the second test case.
 String getCode() – assuming that length of Reservation code is dividable by 3 ; this function
return code of RC as the rule:
o Code of RC = separate a RC into groups, each group has exactly 3 characters with
same order of orginal RC, groups are seperated by character “-“, eg A12-BE2-
CMK
The program output might look something like:

No of test Correct output


case
2
1

Đề 11 – bài 16
Question 1:
Write a class named Fan that holds information of a fan
Where:
· Fan() - Default Constructor.
. Fan(code:String,price:double) -Parameterized
constructor, which sets values to code and price.
· getCode(): String - return code in uppercase format.
· getPrice(): double - return price.
. setPrice(price:double): void - update the value of price.
Question 2:
Write a class named Car that holds information about a
Car and class named VNCar which is derived from
Car(i.e. Car is super class and VNCar is sub class)
Where:
· getName(): String - return name.
· getPrice(): double - return price.
· setPrice(price:double): void - update price.
. toString():String - return the string of format:
name price

Where:
· getSalePrice(): double - return the value
price1=price+inc, where inc = 10% of
price if series<300, = 0 otherwise.
. toString():String - return the string of format:
name price series

Question 3:
Write a class named Fan that holds information about a
fan
Where:
· getCode(): String - return code.
· getPrice(): double - return price.
· setCode(code:String): void - update code.
· setPrice(price:double): void - update price.
Do not format the result.

Write a class named MyFan, which implements the


interface IFan. The class MyFan implements
methods f1, f2 and f3 in IFan interface as below:
. f1: Increase the price by 10% for those fans (in the list t)
having code starts with xCode (see
sample output).
. f2: count and return the number of fans (in the list t)
having price <= xPrice.
. f3: sort all fans (in the list t) ascendingly by price, in case
their prices are the same, sort them ascendingly by their
code alphabetically. The sorting must ignore case during
the comparation.
In the main() function, the list t already contains some
data and you can realize it from the output.

When running, the program output might look something


like:

Question 4:
The interface IString below is already compiled and given
in byte code format, thus you can use it without creating
IString.java file
Write a class named MyString, which implements the
interface IString. The class MyString implements methods
f1 and f2 in IString interface as below:
. f1: calculate and return sum of all digits in str.
. f2: return the string s, which is obtained by reading all
characters in str, if a character is a digit
between 0 and 8 then increase it by 1 (others characters
are unchanged). E.g., if
str="a01b2c8d9" then s="a12b3c9d9"

The program output might look something like:

Đề 13
Giống 3 câu đề 11 ( output câu 3
khác)
Question1:
(3 marks) You have main function which is saved on folder named Q1 already. Use these
classes and functions to test all your operations in this question, DO NOT EDIT ANY CODE
in main function. You can add more operations/classes/interfaces to be able to answer the
below question.

Design and code a class named Employee that holds information about a Employee.
Information of an Employee includes:
 A string describes the name of an Employee.
 A double value describes basic salary of an Employee.
Include the following member functions in your design:

 Constructors to set values for instance variables.


 Add needed operations to the class.
Design and code a deriving class named Seller from Employee class that holds information
about a Seller. Information of a Seller includes:
 A double value describes revenue of a Seller of a year.
Include the following member functions in your design:

 Constructors to set values for instance variables.


 Add needed operations to the class so that the main function can be run and complete the
below method which is declared in Seller class, the function will be used in second test case.
o double getSalary() – use to determine sale price of a seller; salary = basic salary +
bonus, where:
 bonus = 0.0005 percent out of revenue if revenue < 30000.
 otherwise bonus = 0.00001 percent out of revenue.
salary shoude be arounded tho the closest double value with tie rounding up if Seller name
start with letter “C” or”c”, ortherwisre the salary shoude be a rounded to the closest double value
with ties rounding down

The program output might look something like:

No of test Correct output Correct output


case
2 Enter employee name: Anton Enter employee name: Canton

Enter employee salary: 1500 Enter employee salary: 1500

Enter employee revenue: 31000 Enter employee revenue: 31000

Enter TC: 2 Enter TC: 2

OUTPUT: OUTPUT:

1500.0 1501.0
1 Enter employee name: Anton

Enter employee salary: 1500

Enter employee revenue: 31000


Enter TC: 1

OUTPUT:

Anton 1500.0

Anton 1500.0 31000.0

Question 2:
(4 Point) You have main function which is saved on folder named Q2 already. Use these
classes and function to test all your operations in this question, DO NOT EDIT ANY CODE
in main. You can add more operations/classes/interfaces to be able to answer the below
questions.
We had provided you:
1. Interface – ICourse which will declare some operations for a Course – DO NOT EDIT this
one.
2. You only need to complete the code in class MyCourse and Course.
Design and code a class named Course that holds information about a Course. Information of
a Course includes:
 A double value holding fee of a Course.
 A string describing name of a Course.
Include the following member functions in your design:

 Constructors to set values for instance variables.


 Add needed operations to the class so that the main function can be run and complete the
function
o String getName() – return name of a Course.
Design and code a class named MyCourse which will implement interface ICourse and complete 2
methods which were declared in ICourse

 void f1(List<Course> a, int st) – Sort the list of courses "a" ascending by course fee if st = 1
otherwise move all of course (int the same order as original list) in the list ”a” which have fee
is less than or equals 120

 int f2(List<Course> a, double fee) - count and return numbers of courses in the list “a” which
are in the list “a” and has course fee greater than or equals given fee.

Given some data which is added to list “a” in the Main already:

Course name Course fee

PRJ311 110

DBI202 150

PRF192 120
By using given data, the program output might look something like:

Add more how many course: 1

Course name: PRN292

Course fee: 180.0

Enter test function (1-f1;2-f2): 1

Enter st: 2

OUTPUT:

DBI202

PRN292

Question 3 (3 Point) You have main function which is saved on folder named Q3
already. Use these classes and functions to test all your operations in this question, DO NOT
EDIT ANY CODE in main function. You can add more operations/classes/interfaces to be
able to answer the below question.

Design and code a class named ReservationCode that holds information of a


ReservationCode (RC) for a customer, including:
 A string describes value of a customer name.
 A string describes value for a RC.
Include the following member functions in your design:

 Constructors to set values for instance variables.


 Add needed operations to the class and complete below method which is declared in
ReservationCode class, the function will be used in the second test case.
 String getCode();this function return code of RC as the rule:
oCode of RC = increment all letters (other characters are unchanged) only in the
given string of RC by 1:a->b,b->c,c->d,…->z,z->a, this increment is applied same
rule for upper characters
The program output might look something like:

No of test Correct output


case
2 Enter customer name: Ab12cDz45

Enter reservation code: K2M1D9

Enter TC: 2

OUTPUT:

Bc12dEa45
1

Đề 15
Question 1:
(3 marks) You have main function which is saved on folder named Q1 already. Use these
classes and functions to test all your operations in this question, DO NOT EDIT ANY CODE
in main function. You can add more operations/classes/interfaces to be able to answer the
below question.

Design and code a class named Motor that holds information about a Motor. Information of a
Motor includes:
 A string describes the brand name of a Motor.
 A double value describes price of a Motor.
Include the following member functions in your design:

 Constructors to set values for instance variables.


 Add needed operations to the class.
Design and code a deriving class named VNMotor from Motor class that holds information
about a VNMotor. Information of a VNMotor includes:
 A String describes the series of a VNMotor.
Include the following member functions in your design:

 Constructors to set values for instance variables.


 Add needed operations to the class so that the main function can be run and complete the
below method which is declared in VNMotor class, the function will be used in second test
case.
o double getSalePrice() – use to determine sale price of a Motor, sale price = original
price – discount, where:
 discount = 5 percent out of original price if original price < 3000.
 otherwise discount = 10 percent out of original price.
Do not format the format the result.

The program output might look something like:

No Correct output Correct output


of
test
cas
e
2

Question 2:
(4 Point) You have main function which is saved on folder named Q2 already. Use these
classes and function to test all your operations in this question, DO NOT EDIT ANY CODE
in main. You can add more operations/classes/interfaces to be able to answer the below
questions.
We had provided you:
1. Interface – IPrinter which will declare some operations for Printers – DO NOT EDIT this
one.
2. You only need to complete the code in class MyPrinter and Printer.
Design and code a class named Printer that holds information about a Printer. Information of
a Printer includes:
 A double value holding price of a Printer.
 A string describing name of a Printer.
Include the following member functions in your design:

 Constructors to set values for instance variables.


 Add needed operations to the class so that the main function can be run and complete the
function
o String getName() – return name of a Printer.
Design and code a class named MyPrinter which will implement interface IPrinter and complete 2
methods which were declared in IPrinter:

 void f1(List<Printer> a, double price) – remove from the list of printers "a" all printers which
has price less than or equals to given price.
 int f2(List<Printer> a, String name) - count and return number of printers which are in the list
“a” and has name contains given name. The comparison must ignores the case during
comparison.

Given some data which is added to list “a” in the Main already:

Printer name Printer price

HP 200J 110

HP 2000G 150

Canon G1240 120

By using given data, the program output might look something like:
Question3: (3 Point) You have main function which is saved on folder named Q3
already. Use these classes and functions to test all your operations in this question, DO NOT
EDIT ANY CODE in main function. You can add more operations/classes/interfaces to be
able to answer the below question.

Design and code a class named ReservationCode that holds information of a


ReservationCode (RC) for a customer, including:
 A string describes value of a customer name.
 A string describes value for a RC.
Include the following member functions in your design:

 Constructors to set values for instance variables.


 Add needed operations to the class and complete below method which is declared in
ReservationCode class, the function will be used in the second test case.
 String getCode() – assuming that length of Reservation code is dividable by 2 ; this function
return code of RC as the rule:
o Code of RC = separate a RC into groups, each group has exactly 2 characters with
same order of orginal RC, groups are seperated by character “-“, eg A1-BE-CM
The program output might look something like:

No of test Correct output


case
2

Đề 16:
Question 1:
Design and code a class Noodle that holds information of a Noodle
. getCode(): String - return a code of the Noodle where every
letters are in uppercase.
. getPrice[]: double - return price of the Noodle.
. setPrice[price:double): void - set current price of the Noodle to a
given price.
Do not format the result

Question 2:
Design and code a class Noodle that holds information
about a Noodle and class ColorNoodle which is derived
from Noodle
Where:
1. getPrice():double - return the price of a Noodle.
2. getName():String - return the name of a Noodle.
3. toString():String - return information of a Noodle
as a string as format of name price

. toString[):String - return information of a ColorNoodle


as a string as format of name maker
original price
· getPrice[:double - use to determine price of a
ColorNoodle, price = original price + increment,
where:
. increment = 10 percent out of original price if noodle
name starts with "G" or
. otherwise increment = 0.
Do not format the format the result.

The program output might look something like:


Question 3:
Design and code a class named Noodle that holds
information about a Noodle
Where
1. getPrice():double - return the price of a Noodle.
2. getName():String - return the name of a Noodle.
3. setName(name:String):void - set a given name to
current
name.
4, setPrice(price:double):void - set a given price to current
price
5. You are free to add more methods to the class (if
needed)
. Method named f1: count and return the number of
Noodles in the list "list" which have price less
than or equals to given price "d".
. Method named f2: remove all Noodles in the list "list"
which have price less than or equals to the
price of the first Noodle (including itself).
. Method named f3: return the list of Noodle names (in the
same order) which are in the list "list"and have unique
name in the list. The comparing must ignores case during
the comparison.

Given some data which is added to list "list" in the Main


already:
Question 4:

1. int sum(string:String) - this function return summation


of a given string as the rule:
sum = sum of all numbers in the given string which is less
than the first number in the given
one.
2. String getCode(string:String) - this function return code
of given string "string" as the rule:
o Code of given string = remove all non numerics in the
given string and return the remaining one
(in the same order as original one).
Only one empty space between two words in the result.
The program output might look something like:
Đề 17
Question 1: (2 marks)

Do not pay attention to real meaning of objects, variables and their values in the questions below.

Write a class named Book that holds information of a book.


Book Where:
-title:String  Book() - default constructor.
-price:int  Book(title:String, price:int) - constructor, which
+Book() sets values to title and price.
+Book(title:String, price:int)  getTitle():String – return title in uppercase
+getTitle():String format.
+getPrice():int  getPrice():int – return price.
+setPrice(price:int):void
 setPrice(price:int):void – update price.
Do not format the result.

The program output might look something like:


Enter title: atlanta Enter title: atlanta

Enter price: 12 Enter price: 12

1. Test getTitle() 1. Test getTitle()

2. Test setPrice() 2. Test setPrice()

Enter TC (1 or 2): 1 Enter TC (1 or 2): 2

OUTPUT: Enter new price: 20

ATLANTA OUTPUT:

20

Question 2: (3 marks)

Write a class named Car that holds information about a car and class named SpecCar which
is derived from Car (i.e. Car is super class and SpecCar is sub class).
Car Where:
-maker:String  getMaker():String – return maker.
-price:int  getPrice():int – return price.
+Car()  setMaker(maker:String):void – update maker.
+Car(maker:String, price:int)  toString():String – return the string of format:
+getMaker():String maker, price
+getPrice():int
+setMaker(maker:String):void
+toString():String
Where:
SpecCar  toString():String – return the string of
-type:int format:
maker, price, type
+SpecCar()  setData():void – Add string “XZ” to
+SpecCar(maker:String, price:int, type:int) the head of maker and increase price
+toString():String by 20.
+setData():void  getValue():int – Return price+inc,
+getValue():int
where if type<7 then inc=10,
otherwise inc=15.

The program output might look something like:

Enter maker: hala Enter maker: hala Enter maker: hala Enter maker: hala

Enter price: 500 Enter price: 500 Enter price: 500 Enter price: 500

Enter type: 7 Enter type: 7 Enter type: 6 Enter type: 8

1. Test toString() 1. Test toString() 1. Test toString() 1. Test toString()

2. Test setData() 2. Test setData() 2. Test setData() 2. Test setData()


3. Test getValue() 3. Test getValue() 3. Test getValue() 3. Test getValue()

Enter TC (1,2,3): 1 Enter TC (1,2,3): 2 Enter TC (1,2,3): 3 Enter TC (1,2,3): 3

OUTPUT: OUTPUT: OUTPUT: OUTPUT:

hala, 500 XZhala, 520 510 515

hala, 500, 7

Question 3: (3 marks)

Write a class named Car that holds information about a car.


Car Where:
-maker:String  getMaker():String – return maker.
-rate:int  getRate():int – return rate.
+Car ()  setMaker(maker:String): void – update maker.
+Car (maker:String, rate:int)  setRate(rate:int): void – update rate.
+getMaker():String
+getRate():int
+setMaker(maker:String):void
+setRate(rate:int):void

The interface ICar below is already compiled and given in byte code format, thus you can use it
without creating ICar.java file.

import java.util.List;

public interface ICar {

public int f1(List<Car> t);

public void f2(List<Car> t);

public void f3(List<Car> t);

Write a class named MyCar, which implements the interface ICar. The class MyCar implements
methods f1, f2 and f3 in ICar as below (you can add other functions in MyCar class):

 f1: Return the whole part of average rate of all cars (e.g. the whole part of 3.7 is 3).
 f2: Find the first max and min rates in the list and swap their positions.
 f3: Sort the list by maker alphabetically, in case makers are the same, sort them descendingly
by rate.

When running, the program will add some data to the list. Sample output might look something like:
Add how many elements: 0 Add how many elements: 0
Enter TC(1-f1;2-f2;3-f3): 2
Enter TC(1-f1;2-f2;3-f3): 1
The list before running f2:
The list before running f1: (A,6) (B,2) (C,9) (D,17) (E,8) (F,17) (G,2)
OUTPUT:
(A,3) (B,7) (C,6) (D,7) (E,6) (A,6) (D,17) (C,9) (B,2) (E,8) (F,17) (G,2)
OUTPUT:

Add how many elements: 0


Enter TC(1-f1;2-f2;3-f3): 3
The list before running f3:
(H,1) (G,2) (E,3) (F,4) (E,15) (C,6) (B,7) (A,8)
OUTPUT:
(A,8) (B,7) (C,6) (E,15) (E,3) (F,4) (G,2) (H,1)

Question 4: (2 marks)

The interface IString below is already compiled and given in byte code format, thus you can use it
without creating IString.java file.

public interface IString {

public int f1(String str);

public String f2(String str);

Write a class named MyString, which implements the interface IString. The class MyString
implements methods f1 and f2 in IString as below:

 f1: Count and return number of prime digits in str.


 f2: Reverse order of all words in str (word = a string without space).

The program output might look something like:

1. Test f1() 1. Test f1()

2. Test f2() 2. Test f2()

Enter TC (1 or 2): 1 Enter TC (1 or 2): 2

Enter a string: Enter a string:

a32b 95cd b67 a9 b1 a8 a7 a6 a5


OUTPUT: OUTPUT:

4 a5 a6 a7 a8 b1 a9

Đề PE – HL – SP2023
Question 1:
Write a class Cala and a class SpecCala extending from
Cala(i.e. Cala is a superclass and SpecCala is a subclass)
with the following information:

Where:

· getOwner():String - return owner.


· getPrice():int - return price.
· setOwner(owner:String):void - update owner.
. toString():String - return the string of format:
owner @ price
Where
. toString():String - return the string of format:
owner @ price # color

. setData():void - Formats the owner with the


following rules:
o The first letter of all words is converted to
uppercase.
0 All other letters are converted to lowercase.
. getValue():int -Check if color is even number then
return price+1, otherwise return price*2.
Question 2:
Write a class Cala with the following information:

Where:
getOwner():String - return owner.
getPrice():int - return price.
setOwner(owner:String): void – update owner.
setPrice(price:int): void - update price.
The interface Icala below is already compiled and given in
byte code format, thus you can use it without creating an
Icala.java file
Write a class MyCala, which implements the interface
ICala. The class MyCala implements methods
fl, f2 and f3 in ICala as below (you can add other functions
in MyCala class):
f1: Count and return number of elements that its price is
an even number.
f2: Remove the second element having minimum price (do
nothing if only
one element in the list).
f3: Suppose all owners contain at least 1 character. Sort
the list t
descendingly by the Ist character of the owner.
When running, the program will add some data to the list.
Sample output might look something like:

Question 3:
The interface Istring below is already compiled and given
in byte code format, thus you can use it without creating
Istring.java file.

Write a class named MyString, which implements the


interface IString. The class MyString
implements methods fl and f2 in IString as below:
fl: Count and return number of words containing at least
1 even digit.
f2: Return the string s, which is obtained by replacing the
1st palindrome word in str with the string "YY" (word = a
string without space(s), a word is called palindrome if it
and its reverse are the same). (do nothing if the list doesn't
have any palindrome).
Đề 2 PaperNo_19
Question 1:
Write a class named Bottle that holds information of a
bottle

Where
· Bottle() - default constructor.
· Bottle(maker:String, volume:int) - constructor, which
sets values to maker and volume.
. getMaker[):String - return maker in lowercase
format.
· getVolume():int - return volume.
· setVolume(volume:int):void - update volume.
Do not format the result.

Question 2:
Write a class SpecBrick which is derived from Brick
(i.e.Brick is super class and SpecBrick is sub class)
Where
· getPlace():String - return place.
· getPrice()int - return price.
. setPlace(place:String):void - update place.
* toString():String - return the string of format:
place, price

Where:
. tostring():String - return the string of
format:
place, price, color
. setData[):void - Insert the string "BCA"
into place at position 2 (the first
position is 0].
. getValue():int - Check if color>7 then return price+9,
otherwise return price+6

Question 3:
Write a class named Brick that holds information about a
hat
Where:
· getPlace():String - return place.
· getPricel):int - return price.
· setPlace(place:String): void - update place.
· setPrice(price:int): void - update price.
Write a class named MyBrick, which implements the
interface IBrick. The class MyBrick implements
methods f1, f2 and f3 in IBrick as below (you can add
other functions in MyBrick class):
· f1: Count and return number of elements with place
starting with digit and ending with letter.
. f2: Find the (first) brick having maximum odd price and
change its place to "XX".
. f3: Find the (first) brick having maximum price and sort
all elements before it ascendingly by
price
When running, the program will add some data to the list.
Sample output might look something like:
Question 4

Write a class named MyString, which implements the


interface Istring. The class MyString implements
methods f1 and f2 in IString as below:
. f1: Count and return number of words ending with 'm'
or 'n' (not case sensitive).
. f2: Return the string s, which is obtained by reversing the
(first) longest word in the string str
(word = a string without space(s)).
The program output might look something like:

Đề 3- Paper No2
Question 1:
Write a class Camel with the following information:
Where:
· Camel() - default constructor.
· Camel(desert:String, step:int) - constructor, which
sets values to desert and step.
. getDesert():String - return desert in lowercase
format.
· getStep():int - return step.
· setStep(step:int):void - update step.
Do not format the result.
Question 2:
Write a class Cala and a class SpecCala extending
from Cala (i.e. Cala is superclass and SpecCala is a
subeclass) with the following information

Where:
. getOwner():String - return owner.
. getPrice():int - return price.
· setOwner(owner:String):void - update owner.
. toString():String - return the string of format:
owner, price
Where:
. toString():String - return the string of
format:
owner, price, color
. setData():void - Replace the 2nd character
in owner with the string "XX".
. getValue():int - Check if color is odd
number then return price+3, otherwise
return price+7.

Question 3:
Write a class Cala with the following information
Where:
· getOwner():String - return owner.
· getPrice():int - return price.
· setOwner(owner:String): void - update owner.
· setPrice(price:int): void - update price.

When running, the program will add some data to


the list. Sample output might look something like:
Question 4:
The interface Istring below is already compiled and
given in byte code format, thus you can use it
without creating IString.java file

Write a class named MyString, which implements


the interface IString. The class MyString
implements methods f1 and f2 in IString as below:
. f1: Count and return number of words containing
at least 1 odd digit.
. f2: Return the string s, which is obtained by
replacing the (first) palindrom word in str with the
string "XX" (word = a string without space(s), a
word is called palindrom if it and its reverse are
the same).

The program output might look something like:


Đề SU23 ca 14h
Question 1
Write a class ElectricMotor with the following
information:

Where:
ElectricMotor() - default constructor.
ElectricMotor(name:String, voltage:int,current:int)
- constructor, which sets values to name, voltage and
current of the electric motor.
getName():String - retums the name of the motor in
uppercase format.
getPower(): int - returns the motor power calculated
as voltage times current
setVoltage(volt:int):void - voltage update.
Valid values are between 110 and 220. If it is
out of range, print out "Invalid value"
setCurrent(curr.int):void - current update.
Valid value is greater than 0. If value is less
than or equal to 0, print out "Invalid value"

Question 2:
An interface called Flower is given as follows,
therefore you do not need to write it yourseft

Where:
unitPrice: final static variable contains price for
each Flower
You create a Daisy class that implements the Flower
interface as follows:
Where :
 You need to override all abstract in Flower
interface as follows:
 . bloom_at(int currHour): int - Calculate at
what hour(from currHour) a flower will bloom
(all hours are in 24 hours format). Return
bloomHour = currHour + 5. If bloomHour>24-
>bloomHour -= 24 to ensure valid format of
bloomHour. For example: if we set currHour is
23:00 at night, then it will bloom at 23:00+5 -24=
4:00 on the next morning day.
 . fade_at(int currHour):int - Calculate at what
hour (from currHour), a flower will be faded
( all hours are in 24 hours format). Rerturn
fadeHour = currHour + 10. If fadeHour>24-
>fadeHour -= 24 to ensure valid hour format of
fadeHour. For example: if we set currHour is
23:00 at night, then it will die at 23:00+10 -24=
9:00 on the next morning day.
 . price(int numOfFlower):int - Return the price
using this formular: price=Flower. unitPrice *
numOfFlower

Question 3:
Write a class Employee with the following
information
Where:
· Employee ():default Constructor.
.Employee(id:int,firstName:String,lastName:Str
ing,salary:int):Constructor with
id,firstName,lastName and salary.
· getlD():int-return employee id.
· getfirstName():String-return employee first
name.
· getlastName[):String-return employee last
name.
· getSalary():int-return employee salary.
· setID(id:int):void - set employee id.
setFirstName(firstName:String):void-set
employee first name.
. setLastName(lastName:String):vold-set
employee last name.
· setSalary(salary:int):void-set employee salary.
. getName[]-String-return the employee's name.
. getAnnualSalaryl):int-return the employee
salary*12.
. raiseSalary[percent:int]:int-return the
employee raise salary percent.
. toString():String: overriding the toString
method and return a string following format
"Employee[id="*,name="",salary=""]".
Hint: a name includes a last name, "" and a first
name.
Question 4
You task is to write called StringProcessor with
this UML:
Where:
. match_student_id(String s): static boolean - A
static function which verifies whether a student
ID is correct. The student ID must start with
se,he, or qe(ignore case) followed by exactly 4 to
6 digits.For example: SE1234 is a correct ID but
SE1234$ is not. Or hE1111 is a correct ID but
hhE1111 is not.
. format_camel(String): static String - A static
function which converts a string
from"underscore" format to "camel" format.
For example: format_camel will be transformed
into formatCamel using this function.
Đề FA23 11h30 HCM
Question 1:
Write a class Product with the following information:
Where:

. Product 0 - default constructor


. Product[id:int, name:String, price:double,
quantity:int, discount:int) - parameterized
constructor, which sets values to id, name,
price, quantity, and discount.
. setDiscount(int discount):void - update
discount. If discount less than 0 then set to
0
. toString(): String - return string of format
Of the Product: id,name,price,quantity, subTotal
with subTotal = quantity * price * [100-
discount)/100. The price and subTotal are
formatted two decimal places.
Question 2:
Write a class Car and a class SpecCar extending from
Car(i.e. Car is a super class and SpecCar is a sub
class) with the following information:

Where:
· Car () - default constructor
· Car(name:String, price:double) - parameterized
constructor, which sets values to name and price
· getName():String - return name in uppercase.
· getPrice():double - return price.
. toString():String - return the string of format :
name, price. The price is formatted in two decimal
places.
Where
. SpecCar() - default constructor
· SpecCar(name:String, price:double, warranty:int) -
parameterized constructor, which sets values to
name, price, and warranty
. toString():String - return the string of format:
name, price, warranty. The name is in uppercase,
the price is formatted in two decimal places.
· getWarranty():int - if name is "Audi" (not case
sensitive) then return warranty + 5, otherwise return
warranty + 2

Question 3:
Write a class Item with the following information
Where:
. Item I) - default constructor
. Item[name:String, quantity:int) - parameterized
constructor, which sets values to name and quantity
. getName[):String - return name in uppercase
. getQuantity()int - return quantity
. toString():String - return the string of format:
name, quantity. The name in uppercase
Write a class named ItemList which extends from
ArrayList(ArrayList is a collection) with the
following information:

Where:
. addltem[Item item): void - add a new Item
to the collection
. printitemByQuantity(valueint|cvoid - print
list of items with quantity equal to value
. getTotalQuantity():int- retum total quantity
of the items in the collection.

Question 4
The interface Iprocess below is already given in java
code format, thus you can use it without creating
IProcess.java file
Write a class named MyClass, which implements the
IProcess interface. The MyClass class implements all
methods in IProcess as below:
. countWords(str1:String, str2:String):int - count the
number of words in the string str1 that are
equal to the string str2 (not case sensitive).
. getLastWord(str:String):String - return the last
word in the string str with the first letter in
uppercase

The program output might look something like this:

Đề Block 5 Fall23 Hola


Question 1:
Write a class named House with the following
information:
Where:
· House() - default constructor.
· House(type:String, area:int) - constructor, which
sets values to type and area.
. getType():String - returns a string s, which is
obtained by taking the 3 last characters of string and
reverse the s string.
· getArea():int - return area.
· setArea(area:int):void - update area=3*new area.
Do not format the result.
Question 2:
Write a class Lift and a class SpecLift extending from
Lift(i.e. Lift is a superclass and SpecLift is a subclass)
with the following information:

Where:
. getLabel():String - return label.
· getType[):int - return type.
· setLabel(label:String):void - update label.
. toStringl):String - return the string of format:
label, type

Where:
. toString():String - return the string of
format: label, load, type
. setData():void - Remove the label
characters with even indexes.
. getValue(]:int - Check if the label does
not contain the type then return load,
otherwise return load + type.

Question 3:
Write a class Lift with the following information
Where:
· getLabel(]:String - return label.
. getLoad(]:int - return load.
· setLabel(label:String): void - update label.
. setLoad(load:int): void - update load.

Write a class MyLift, which implements the interface


ILift. The class MyLift implements methods f1, f2
and f3 in ILift as below (you can add other functions
in MyLift class):

. f1: Calculate the maximum of loads of the elements


whose label has the prime length (Assume
that there are at least 1 element that satisfies the
condition).
(A prime is a natural number greater than 1 that is
not a product of two smaller natural numbers)

. f2: Reverse the first 5 elements in the list (other


elements are unchanged).
. f3: Remove the second element having load < 20
(Assume that there are at least 2 elements that
satisfy the condition).
Question 4:
The interface Istring below is already compiled and
given in byte code format, thus you can use it without
creating IString.java file

Write a class named MyString, which implements the


interface IString. The class MyString implements
methods f1 and f2 in IString as below:
. f1: Count of words are palindrome string and have
at least three number characters (word = a
string without space(s); The palindrome string is the
string after reversal and the original string is exactly
the same, for example "aba" is a palindrome string).
. f2: Return the string by removing odd number
characters that appear more than once in the
string and keep only the first even number character.

The program output might look something like:

Đề Ca 7 Fall23
Question 1:
Write a class named Truck with the following
information:
Where:
· Truck() - default constructor.
· Truck(name:String, weight:int) - constructor, which
sets values to name and weight.
. getName():String - returns a string s, which is
obtained by combining the second and third
characters of the string, then reversing that string.
· getWeight():int - return weight.
· setWeight(weight:int):void - update weight=new
weight + length of name.
Do not format the result.

Question 2:
Write a class Train and a class SpecTrain extending
from Train(i.e. Train is a superclass and SpecTrain is
a subclass)
Where:
· getName():String - return name.
· getType():String - return type.
· setName(name:String):void - update name.
. toString():String - return the string of format:
name, type

Where:
. toString():String - return the string of
format:
name, load, type
. setData():void - Remove the first character of Name.
. getValue():int - Check if the type contains only one
numeric character, return load * length of name,
otherwise return load.

Question 3:
Write a class Train with the following information

Where
 getName(): String – return name
 getLoad(): int-return load
 setName(name:String):void-update name
 setLoad(load:int): void – update load

Write a class MyTrain, which implements the


interface ITrain. The class MyTrain implements
methods f1, f2 and f3 in ITrain as below (you can add
other functions in MyTrain class):
. f1: Sum load of elements whose name containing only 1
'A' character or only 1 'B' character (ignore other
characters).
. f2: Move the first train with minimum load to the
end of the list.
· f3: Remove the second element having maximum
length name (If there is no satisfying element,
then do nothing).

When running, the program will add some data to the


list. Sample output might look something like:
Question 4:
The interface Istring below is already compiled and
given in byte code format, thus you can use it without
creating Istring.java file

Write a class named MyString, which implements the


interface IString. The class MyString implements
methods f1 and f2 in IString as below:

. f1: Count and return number of words starting with


the digit and ending with the non-digit (word
= a string without space(s)].
. f2: Return the string by removing the second word
that contains only 1 digits in the string str
(word = a string without space(s]). If the
requirements are not satisfied, do nothing.

The program output might look something like:

Đề BL3W Hola SU23


Question 1:
Write a class named Table with the following
information:

Where:
· Table() - default constructor.
. Table(name:String, leg:int) - constructor, which sets
values to name and leg.
. getName():String - returns a string s, which is
obtained by taking the 3 last characters of string and
lower case the second character in the s string.
· getLeg():int - return leg.
· setLeg(leg:int):void - update leg.
Do not format the result.

Question2:
Write a class Taxi and a class SpecTaxi extending
from Taxi (i.e. Taxi is a superclass and SpecTaxi is a
subclass)
Where:
getDriver(): String – return driver
· getAge():int - return age.
· setDriver(driver:String):void - update driver.
. toString():String - return the string of format:
driver, age

Where:
. toString():String - return the string of format:
driver, age, salary
. setData():void - Change the 2nd
character of the driver with age.
. getValue():int - Check if the unit digit of age is an
even number, return the salary, otherwise return the
salary + age

Question 3:
Write a class Taxi with the following information

Where:
· getDriver():String - return driver.
· getSalary():int - return salary.
· setDriver(driver:String): void - update driver.
· setSalary(salary:int): void - update salary.

Write a class MyTaxi, which implements the interface


ITaxi. The class MyTaxi implements methods f1,
f2 and f3 in ITaxi as below (you can add other
functions in MyTaxi class):

. f1: Calculate the total number of salarys of an


element whose driver has at least two characters
and is not a palindrome string (The palindrome string
is the string after reversal and the original
string is exoctly the same, for example "aba" is a
palindrome string).
. f2: Remove the first element whose salary is a 2-digit
number with 2 even digits (if the conditions
are not satisfied, do nothing).
. f3: Sort elements by salary descending, in case
salarys are the same, sort them ascending ly by
driver.
When running, the program will add some data to the
list. Sample output might look something like:

Question 4:
The interface IString below is already compiled and
given in byte code format, thus you can use it
withtout creating IString.java file

Write a class named MyString, which implements the


interface IString. The class MyString implements
methods f1 and f2 in IString as below:
. f1: Count of words are palindrome strings and have
at least two characters (word = a string
without space(s); The palindrome string is the string
after reversal and the original string is
exactly the same, for example "aba" is a palindrome
string).
. f2: Find the first word with the longest length in the
string (word = a string without space(s)).

The program output might look something like:

Đề ca 4 SUM23
Question 1:
Write a class Product
Where
. Product () - default constructor
· Product(id:int, name:String, price:double,
quantity:int, discount:int) - constructor, which sets
values to id, name, price, quantity, and discount
(default discount = 0)
· setDiscount(int discount):void – update discount
· subTotal():double – return subtotal [subtotal =
quantity * price * (100-discount)/100]
Question 2:
Write a class Product and a class Smartphone
extending from Product(i.e. Product is a superclass
and Smartphone is a subclass)

Where:
Product(code:String, name:String) – constructor,
which sets values to code and name.

Where:
. Smartphone(code:String, name:String,
internal_memory:int, weight: float, price:int) -
constructor, which sets values to code, name,
internal_memory, weight and price.
· showinfor(): Print product information:
scode +"-" + name +"-" + internal_memory
+"GB" +"-"+ weight+"g"+"-"+ price +"$"
. buyNow( int quantity) : Returns the total
payment according to the following description:
-If the product is "IPHONE 14
PROMAX" with quantity>=5, then
20% off total payment, otherwise no
discount.
Total payment=quantity*price
Question3
A student class is missing is partially written for you,
so you need to complete the rest:

Where:
. Student(String id,String name,double gpa):
Constructor of Student
class, this function is already written for you.
. compareTo(Object o): int- You need to compare
name of 2 students according to alphabert table, if 2
students have the same name, then we sort
ascendently by their gpa. The function will support
for Collections.sort function in next class.
You are supposed to write missing part of a class
named ProcrssStudent with :
Where:
· sortStudent(List<Student> li):void: Sort
student by: first priority is name of
students. If 2 students have the same
name, we sort by gpa. Hint: you can use
Collections.sort(li) if you have already
implemented compareTo method in
Student class.
· find_by_partial_name(List<Student>
li,String letter):List<Student> - Find all
students with partial name. For
example: If we find student with "N",
"Nam", "Nhan" will be matched but not
"An".
. find_higher_gpa(List<Student> li,int
gpa):List<Student> - Find all students
whose gpa is higher the given gpa
parameter.
Question 4:
Write the interface according to the following

Write a class named Item, which implements the


interface Iservice. The class Item is as below
Where:
· Item(id:String,name:String, size:int) - constructor,
which sets values to the given parameters.
. formatSize() : return a new string depends on the
size, id fields as the table following.

. formatName() : return a new string that is


removed leading, trailing spaces and extra spaces
from the name field. For example:
if the name is " oversized striped blazer "
then return a new string: "oversized striped
blazer"
Đề Ca 6 Fall 23
Question 1:
Write a class Plane

Where
· Plane():default constructor
. Plane(type:String,capacity:int,x:float,y:float):
parameterized
constructor, which sets values to type, capacity, x, and
y
· Getters and Setters: getter and setter of each
attribute in the
class
. toString(): String - return a string format of the
Plane as follows:
type-capactityil(x,y)
For example: type="AirBusA320", capactity=320,
x=4.5, y=3.4,
then the output should be: AirBusA320-320#|
4.5000,3.4000)
with x, y are formatted with four decimal places
. getDirection(): String - get directions of a plane
based on its
location and divided into 05 cases:
- if x>0 and y>0 then return "NE"
if x>0 and y<O then return "SE"
if x<0 and y>0 then return "NW"
if x<0 and y<0 then return "SW"
if x=0 or y=0 then return "X"
Question 2:
Write a class named Staff and a class named
Engineer extended from Staff( i.e. Staff is a super
class and Engineer is a subclass) with the

Where:
· Staff() - default constructor
· Staff (id:int, salary:int) - parameterized
constructor which sets values to id and
salary
. getld(): int - return id
· getSalary(): int - return salary
· setSalary(salary: int): void - update the
salary. If the salary is less than 1000 then
set it to 1000
. toString(): String - return a string format of
the Staff: id, salary

Where:
· Engineer(id:int, salary:int, benefits:int) -
parameterized constructor, which sets
values to id, salary, and benefits.
· getBenefits (): int - return benefits.
. setBenefits(benefits:int): void - update
benefits.
getGrossSalary():int - return the gross
salary of the engineer with the following
expression: gross salary = salary + benefits
. toString(): String - returns a string format of
the Engineer: id, salary, benefits, gross
salary
Question 3:
Write a class named Product with the

Where:
· Product() - default constructor
· Product(id:int, name:String, price:double) -
parameterized constructor: set values to the
id, name, and price
. getid[]:int - return the id
. setName(name: String): void - set the name
to the name property
. getName():String - return the name in
uppercase
· setPrice[price: double): void - set the price to
the price property
· getPrice(]:double - return the price
. toString(): String - return the string format of
the Product: id, name, price. The price is
formatted with two decimal places
Write a class ProductList which extends from
ArrayList(ArrayList is a collection)
ProductList
Where
getProductById(): Product –
getProductWithMinPrice(): Product – return the
product with the smallest price
Question 4:
The interface Protocol below is already given in java
code format, thus you can use it without creating a
Protocol.java file

Write a class named Server( in the default package),


which implements the Protocol interface. The Server
class implements methods of the Protocol as below:
Where:
. sendMessage[data:String): String - returns a string
in the
following format:
"65535":data.length():data
For example: data="hello world" then the output
string
is: "65535:11:hello world"
. receivePacket(data:String): String - return the
string after the
last colon of the data string.
For example, if data string is : 65535:000004:abcd"
then output string is "abcd"

Đề ca 5 Fall23
Question 1:
Write a class Profession()

Where:
· Profession(): default constructor - set the default
values of the fields: name is "Nguyen Van A", age is
20, and major is "Student.".
· Profession (name: String, age: int, major: String): -
parameterized constructor, which sets values to
name, age, and major. If the age is less than 20 then
set it to 20
· getName():String - return name
· setName(name: String): void - update name. If
name
is "N/A" (not case sensitive) then set name is "No
name"
. toString(): String; return a string with the format:
name-age-major
Question 2:(thiếu dữ kiện)
Create a class named Employee

Where:
· Employee(): - default constructor
· Employee (code:String, name:String,
baseSalary: int) - parameterized constructor,
which sets values to code, name and
baseSalary.
Create a class named HRManager that extends the
Employee class
HRManager

exprear. Int) parametenzeu constructor, WmCn sets


values to code, name, baseSalary and expYear.
toString():String - return employee information:
code,name,expYear,baseSalary(VND)
getSalary(): int - return the salary with the following
expression:
-If the expYear >=5 then salary = baseSalary +
expYear* 1000000, otherwise salary = baseSalary
Question3
Write a class named Student

Where:
. Student() :- default constructor
· Student(id: String, name: String, gpa: double) -
parameterized
constructor, which sets values to id, name and gpa.
The id in
uppercase
· getGpa():double - return gpa
. getName():String - return name
. toString():String - return the string format of the
Student:
id-name-gpa. The gpa is formatted two the decimal
places

Where:
· findByName(strName:String):List<Student>
returns a list of students whose names are equal
to strName (not case sensitive) if found,
otherwise returns a null value.
· findByGpa(nGpa: double): List<Student> -
returns a list of students whose gpas are greater
than or equal to nGpa if found, otherwise returns
a null value.
Question 4
The interface ImyString below is already given in
java code format, thus you can use it without creating
an IMyString.java file

-Write a class named StringProcessor (in the default


package), which implements the IMyString interface.
The StringProcessor class implements methods of the
IMyString as below:

· removeSpaces(sentence: String): String - removes


extra spaces in the sentence and returns a
sentence with each word separated by only one space
. countWordByString(sentence: String, str: String):
int - return the number of words in a sentence that
begins with the string str (not case sensitive)
-The program output might look something like this:

Đề Block5 Sum23
Question 1:
Write a class Date
Where:
· Date()- default constructor.
. getDay():int - return Day value.
· getMonth():int - return Month value.
· getYear():int - return Year value.
· setDay(day:int):void - set Day value.
. setMonth(month:int):void-set Month
value.
· setYear(year:int):void - set Year value.
· setDate(day:int,month:int,year:int):void -
set Day, Month and Year value.
. toString():String- overriding the toString
method and return a string following
format "dd/mm/yyyy" with leading zero.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy