PRO192
PRO192
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
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.
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:
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:
Đề 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.
. 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:
Đề 4
Question 2:
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.
Đề 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()
Invoice
MyInvoice
name to customer: Ha
Total amount: 77
name to customer: Ha
Total amount: 96
Đề 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
. 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.
Question 4:
You are given an interface named IString (Do not edit this
one). Design a class MyString which will implement the
interface IString.
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.
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.
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:
HP 200J 110
HP 2000G 150
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.
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:
Đề 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
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
(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.
Enter TC: 2
OUTPUT:
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:
OUTPUT:
Med
OUTPUT:
Kia
OUTPUT:
OUTPUT:
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:
Enter TC: 1
OUTPUT:
Enter TC: 2
OUTPUT:
Hai
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
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.
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:
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:
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.
Đề 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.
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"
Đề 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:
OUTPUT: OUTPUT:
1500.0 1501.0
1 Enter employee name: Anton
OUTPUT:
Anton 1500.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:
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:
PRJ311 110
DBI202 150
PRF192 120
By using given data, the program output might look something like:
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.
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:
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:
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:
HP 200J 110
HP 2000G 150
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.
Đề 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
Do not pay attention to real meaning of objects, variables and their values in the questions below.
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.
Enter maker: hala Enter maker: hala Enter maker: hala Enter maker: hala
Enter price: 500 Enter price: 500 Enter price: 500 Enter price: 500
hala, 500, 7
Question 3: (3 marks)
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;
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:
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:
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:
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.
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
Đề 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.
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:
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
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.
Đề 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
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.
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
Đề 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
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
Đề 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
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
Đề 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.