Exam Code(s): CPT120


Study Period 3, 2019 Sample Exam
University RMIT University
Exam Code(s): CPT120
Title of Paper: Introduction To Programming
Exam Duration: 2 hours
Reading Time: 10 minutes
During an exam, you must not have in your possession, a book, notes, paper, electronic device(s), calculator,
pencil case, mobile phone, smart watch/device or other material/item which has not been authorised for the
exam or specifically permitted as noted below. Any material or item on your desk, chair or person will be
deemed to be in your possession. You are reminded that possession of unauthorised materials in an exam is a
disciplinary offence.
No examination papers are to be removed from the room.
Authorised Materials
Calculators ☐ Yes ☒ No
Open Book ☐ Yes ☒ No
Specifically Permitted Items ☐ Yes ☒ No
If yes, specifically permitted items are:
Students must complete this section if required to write answers within this paper
OUA ID:
Provider University ID:
Family name:
Other names (in full):
Page 1 of 6
Q1 (10 marks)
public class Q1 {
public static void main(String[] args){
int s=___________________;
if (s<5)
s=5;
String answer="";
int a=1;
while(a<s){
answer=a+answer;
if (a%3==0)
answer="\n"+answer;
a=a+1;
}
System.out.println(answer);
}
}
In the Java program above, fill in the blank with a value that can be assigned to the variable ‘s’ then write only
the output of the program below:
(Tip: Use the reverse/non-printed side of this exam paper for any rough work)
Page 2 of 6
Q2 (14 marks)
Fill in the blanks and complete the code below so that the code is valid and runs as described in the comments
and the output message. You must use primitive data types over class types when possible. (Tip: Use the
reverse/non-printed side of this exam paper for any rough work).
public class Q2{
public static void main(String[] args){
// A data type for a number with a decimal point and a compatible value
____________________ val1=____________________;
// A whole number type and a compatible value
____________________ valB=____________________;
// A data type for a number with a decimal point that is different to val1's type.
____________________ val2=valB;
// A data type for a number with a decimal point but generates an error.
____________________ val3=val1*val2;
System.out.println(val1+" "+val2+" "+val3);
}
}
Which line of code above would generate a compilation error if completed according to the requirements stated
in the comments?
Re-write the above line of code to rectify the error:
Write the output of the program when the corrected code is used:
Page 3 of 6
Q3 (?+?+?+?=26 marks)
Consider the Tower class below which has already been implemented and is available for you to use:
Tower class: A Tower object cannot be created without a x and y coordinates (each a whole number
between 0-9 inclusive) and a type. The type indicates whether it is a digital signal tower or an analogue
signal tower. It has accessors for the information mentioned above. Only its constructor and the said
accessors methods can be accessed by other classes.
Following the Map class requirements below and by using the best object-oriented design guidelines and
practices taught in the unit, write the relevant code in the designated spaces provided.
Map class: A Map object has an array of Tower objects. A Map object cannot be created without a name
value and a value for the maximum array size. A Map object also has the methods addTower,
showTowerMap and showUserInterface. When a Map object is instantiated, it must also call the
showUserInterface method (assume the showUserInterface method is already present). Aside from the
methods, no other component of this class should be accessible by other classes.
The addTower method takes the minimum information required for creating a Tower object as its parameters.
If a Tower object with the same coordinates does not exist in the Tower array of the Map object, a new Tower
object is added to the array, if possible. There must not be multiple objects with the same coordinates in the
array.
The showTowerMap method displays displays a grid of the Tower placements with “dots” to denote where
there is no tower and a D or an A to denote digital or analogue tower respectively. E.g. if there is a digtal
tower at 0,5 (x,y) and analogue towers at 2,3 and 5,2, this method would display in the following format:
Note: Use only standard arrays in Java (e.g. avoid ArrayList, etc.). You must not use break, continue,
System.exit(). Use only while loops for repetition. When possible, you must use concepts covered in standard
class materials over others. Use the reverse/non-printed side of this exam paper for any rough work.
Write below the code for any member variable declarations of the Map class.
Page 4 of 6
Write below the code for any definitions and implementations of a constructor of the Map class:
Write below the code for the definition and implementation of the addTower method of the Map class:
Page 5 of 6
Write below the code for the definition and implementation of the showTowerMap method of the Map class:
(END OF EXAM QUESTIONS)
Page 6 of 6

如有需要,请加QQ99515681 或微信:codehelp

猜你喜欢

转载自www.cnblogs.com/mywelh/p/11868819.html
今日推荐