CSD201_-_SP23_-_PE_84.webp
Q

CSD201_-_SP23_-_PE_84.webp

Do not pay attention to real meaning of objects, variables and their values in the questions below.
Question 1: (4 marks)
In this question you should complete some methods in MyList.java file.
The class Bike with 3 data members: brand, color and weight is given and you do not need to edit it. The MyList class is a linked list of Bike objects. The following methods should be completed:
void addLast(String xBrand, int xColor, int xWeight) check if xBrand.charAt(0) == 'B' then do nothing, otherwise add new node with brand=xBrand, color=xColor, weight=xWeight to the end of the list. (color and weight can get arbitrary, even negative values).
• void f1()- Do not edit this method. Your task is to complete the addLast(...) method above only.Output in the file f1.txt must be the following:(A,9,8) (C,6,5) (D,2,4) (Ε,7,9) (F,4,-7) (G,-3,2)
• void f2()-There are 2 given Bike objects x, y in this function. Suppose the list contains at least 3 elements. Write statements to insert x and y to the list so that x will be the 2nd, y will be the 5th node. Output in the file f2.txt must be the following:(C,9,8) (D,6,3) (Ε,8,5) (F,5,4) (1,4,9) (1,3,7)
1
(C,9,8) (X,1,2) (D,6,3) (Ε,8,5) (Y,3,4) (F,5,4) (1,4,9) (1,3,7)
void f3() - Remove the second node having min color (thus if there is only one min color then do nothing). Output in the file f3.txt must be the following:(C,8,6) (D,3,8) (Ε,9,2) (F,5,8) (G,3,7) (Η,6,8) (1,7,3)
(C,8,6) (D,3,8) (Ε,9,2) (F,5,8) (Η,6,8) (1,7,3)
+ 100%
Zoom
Close
Chưa có bình luận nào.

Thông tin

Category
CSD201
Thêm bởi
QuocAnh91
Ngày thêm
Lượt xem
1,394
Lượt bình luận
0
Rating
0.00 star(s) 0 đánh giá

Share this media

Back
Bên trên Bottom