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

192 Po

The document provides instructions for completing a programming exam (PE). Students are only allowed to use their computer materials and online meeting software. They must create folders to save projects, complete questions by modifying given projects, run clean and build, and rename and submit folders. The document also contains sample outputs for 4 exam questions involving classes like Book, Car, SpecCar, MyCar, MyString and interfaces like ICar and IString.

Uploaded by

Cuong Nguyen
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)
13 views

192 Po

The document provides instructions for completing a programming exam (PE). Students are only allowed to use their computer materials and online meeting software. They must create folders to save projects, complete questions by modifying given projects, run clean and build, and rename and submit folders. The document also contains sample outputs for 4 exam questions involving classes like Book, Car, SpecCar, MyCar, MyString and interfaces like ICar and IString.

Uploaded by

Cuong Nguyen
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

PRO192 PE INSTRUCTIONS

Read the instructions below carefully before start coding.


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

1. Create a folder to save given projects, e.g. PRO_given (1). Down load given materials to (1).
2. Steps to do question 1 (do the same for other questions): Open NetBeans, open the given Q1 project,
then complete it according to the requirements in the exam. (Do not: delete or edit given files, or create
java file with the same name as given files).
3. Before submission: Run the function "Clean and Build Project" (Shift+F11), then rename the folder
dist to RUN (or run). (If the folder RUN already exists, delete it before renaming).
4. Submission: to submit the project Q1, at first you must select Question No = 1, browse and select the
project folder (e.g. 1, Q1 or Q1X,...) then click the Submit button. Do the same for other questions. Do
not submit the un-edited given project.
5. Do not use accented Vietnamese when writing comments in programs.
6. Software tools must be used: NetBeans IDE 8.x and Java JDK 1.8.
If at least one of the above requirements is not followed, the exam will get ZERO.
Trouble shooting:
If the given project (e.g. Q1) runs with error, you need to run "Clean and Build Project" (Shift+F11). If still
error, try to rename the project, e.g. from Q1 to Q1X or Q1Y,...
If the size of the project is too large for submission, try to delete the folder "build".

Do not pay attention to real meaning of objects, variables and their values in the questions below.
Question 1: (2 marks)

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 format.
+getTitle():String  getPrice():int – return price.
+getPrice():int
+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:

1
-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
+getPrice():int maker, price
+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  getValue():int – Return price+inc,
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);
}

2
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): 1 Enter TC(1-f1;2-f2;3-f3): 2
The list before running f1: The list before running f2:
(A,3) (B,7) (C,6) (D,7) (E,6) (A,6) (B,2) (C,9) (D,17) (E,8) (F,17) (G,2)
OUTPUT: OUTPUT:
5 (A,6) (D,17) (C,9) (B,2) (E,8) (F,17) (G,2)

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

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