0% found this document useful (0 votes)
5 views3 pages

668c82f22ac14b68abbeff67 Assignment

The document contains instructions for a programming exam with four questions focused on creating classes in Java. Each question requires students to implement specific functionalities related to classes such as Bell, Bike, and MyString, along with their respective methods and constructors. Additionally, it provides guidelines for project submission and restrictions on the use of materials during the exam.

Uploaded by

tminhquan912004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

668c82f22ac14b68abbeff67 Assignment

The document contains instructions for a programming exam with four questions focused on creating classes in Java. Each question requires students to implement specific functionalities related to classes such as Bell, Bike, and MyString, along with their respective methods and constructors. Additionally, it provides guidelines for project submission and restrictions on the use of materials during the exam.

Uploaded by

tminhquan912004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Q1 (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 Bell that holds information of a bell.


Bell Where:
-tower:String  Bell() - default constructor.
-sound:int  Bell(tower:String, sound:int) - constructor, which sets
values to tower and sound.
+Bell()
+Bell(tower:String, sound:int)  getTower():String – return tower in uppercase format.
+getTower():String  getSound():int – return sound.
+getSound():int  setSound(sound:int):void – update sound.
+setSound(sound:int):void

Do not format the result.


The program output might look something like:
Enter tower: alala Enter tower: alala
Enter sound: 12 Enter sound: 12
1. Test getTower() 1. Test getTower()
2. Test setSound() 2. Test setSound()
Enter TC (1 or 2): 1 Enter TC (1 or 2): 2
OUTPUT: Enter new sound: 15
ALALA OUTPUT:
15

Q2 (3 marks) Write a class named Bike that holds information about a bike and class named SpecBike
which is derived from Bike (i.e. Bike is super class and SpecBike is sub class).
Bike Where:
-brand:String  getBrand():String – return brand.
-type:int  getType():int – return type.
 setBrand(brand:String):void – update brand.
+Bike()
+Bike(brand:String, type:int)  toString():String – return the string of format:
+getBrand():String brand, type
+getType():int
+setBrand(brand:String):void
+toString():String
Where:
SpecBike  toString():String – return the string of
-weight:int format:
brand, type, weight
+SpecBike()  setData():void – Replace the second
+SpecBike(brand:String, type:int, weight:int) character in brand by the string “XX”.
+toString():String  getValue():int – Check if weight<5 then
+setData():void return type+3, otherwise return type+6.
+getValue():int

The program output might look something like:


Enter brand: abcd Enter brand: abcd Enter brand: abcd Enter brand: abcd
Enter type: 10 Enter type: 10 Enter type: 10 Enter type: 10
Enter weight: 4 Enter weight: 4 Enter weight: 4 Enter weight: 5
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:
abcd, 10 aXXcd, 10 13 16
abcd, 10, 4

1
Q3 (3 marks) Write a class named Bike that holds information about a bat.
Bike Where:
-brand:String  getBrand():String – return brand.
-type:int  getType():int – return type.
 setBrand(brand:String): void – update brand.
+Bike ()
+Bike (brand:String, type:int)  setType(type:int): void – update type.
+getBrand():String
+getType():int
+setBrand(brand:String):void
+setType(type:int):void

The interface IBike below is already compiled and given in byte code format, thus you can use it without
creating IBike.java file.
import java.util.List;
public interface IBike {
public int f1(List<Bike> t);
public void f2(List<Bike> t);
public void f3(List<Bike> t);
}

Write a class named MyBike, which implements the interface IBike. The class MyBike implements methods
f1, f2 and f3 in IBike as below (you can add other functions in MyBike class):
 f1: Count and return number of elements with brand ending with digit.
 f2: Find the (first) bike having maximum type and change its’ brand to XX.
 f3: Suppose the list contains at least 8 elements. Sort first 3 elements ascendingly and last 4
elements descendingly by type.
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): 1 Enter TC(1-f1;2-f2;3-f3): 2
The list before running f1: The list before running f2:
(1A,5) (B2,4) (CT,3) (D1,4) (2E,5) (4F,2) (A,4) (C,3) (B,5) (D,3) (E,5) (F,4)
OUTPUT: OUTPUT:
2 (A,4) (C,3) (XX,5) (D,3) (E,5) (F,4)

Add how many elements: 0


Enter TC(1-f1;2-f2;3-f3): 3
The list before running f3:
(A,8) (D,17) (E,6) (B,5) (E,1) (F,2) (G,12) (H,3)
OUTPUT:
(E,6) (A,8) (D,17) (B,5) (G,12) (H,3) (F,2) (E,1)

Q4 (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 digits in the string str.
 f2: Suppose the character x is the first most frequent character in the string str (in the sample
output below x=’T’). Return the string s, which is obtained by removing from str all words
containing the character x (word=a string without space(s)).
2
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:
a12b3cd aTTb cd de efTuT uv
OUTPUT: OUTPUT:
3 cd de uv

PRO192 PE INSTRUCTIONS
Students are ONLY allowed to use:
 Materials on his/her computer (including JDK, NetBeans...).
 For distance learning: Google Meet, Hangout (for Exam Monitoring Purpose).

Instructions for completing PE:

(In the followings the name of a folder run and src are written in uppercase for the purpose of emphasis, in a
project their case is not important)
 For each quesion:
o DO NOT create new project. You must use the given project and modify it according to
question’s requirements. DO NOT delete given file(s) and DO NOT create file(s) with the same
name as them. DO NOT use package in your code.
o You CAN create more classes/interfaces/methods/variables (if needed).
o Submission: Submission is performed by project: each time only one project is submitted. Just
before submission, you must run the option “Clean and Build Project”, then rename the folder
dist to RUN. You must select the question number (1 for Q1, 2 for Q2,...), browse and select the
whole project (do not compress) and click the button “Submit”.
(The submitted folder must contain 2 subfolders: SRC contains source files and RUN contains jar
file. SRC is already contained in the project. The RUN folder can be created by 2 ways: rename the
folder dist, or create the folder RUN and copy the jar file to it).
If a project is submitted incorrectly, it will get ZERO.

You might also like