668c82f22ac14b68abbeff67 Assignment
668c82f22ac14b68abbeff67 Assignment
Do not pay attention to real meaning of objects, variables and their values in the questions below.
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
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)
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).
(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.