It's UWAweek 17 (1st semester, week 8)

help2005

This forum is provided to promote discussion amongst students enrolled in CITS2005 Object Oriented Programming.

Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

How do I ask a good question?
Displaying selected article
Showing 1 of 93 articles.
Currently 1 other person reading this forum.


 UWA week 17 (1st semester, week 8) ↓
SVG not supported

Login to reply

👍?
helpful
4:51pm Tue 23rd Apr, ANONYMOUS

The MCQ format allows for a direct match between a student's response and the correct answer, facilitating swift marking and clear feedback. It also respects the time constraints of an exam environment, where typically, one minute per question is allocated, the mid-sem was good in terms of allocating extra time to students to answer these questions. Many felt that having multiple answers to one question was not only confusing but poorly implemented, if you wanted to have multiple answers to one question that takes at least 1 min to trace for each value then a question that is only supposed to take 1 min tun into 4-5mins to check each answer, an alternative could be having multiple values per option e.g. a)1,2,2,3 b)3,4,5,6 c)2,3,5,6 yes this can make it even longer but are there any better alternatives to asking these questions? Otherwise, many of us believe these don't provide actual testing and should be scrapped or at least be considered for partial marks instead of 0 or 1 mark >> MQC will be prone to guessing anyway so if you want an accurate portrayal of a student's understanding, and you can't do the questions properly, don't bother with them. Cascading from this >> the ridiculous amount of tracing that was in the exam lead to not having much time for the written questions, which were poorly weighted within the exam... 2 MARKS for 8+ lines of code is not sustainable ever and doesn't reflect or reward the student for proper answers. If tracing and logic wanted to be assessed, this should've been considered accordingly with the type of assessment chosen. In summary the mqc is too vague, and the short answers were too tight not allowing for consideration of multiple ways or answers and time constraint of 1 hour(check out midsem 22nd April lecture for a poor explanation of the answers) So in light of the mid-sem test, I know a lot of people are quite confused and upset with their marks as well as don't understand the explanation given in class so here is some notes and critique I have compiled about the nature of the questions and my explanation for each one so that we can at least get a better idea of how these work: [---------------------------------------------------------------------------------------] Q1: What is the value of x after the above code is run? (Select the single correct answer) a) 6 b) 7 [c) 20 ✓] d) 21 e) 27 f) 28 [---------------------------------------------------------------------------------------] because it's basically saying give the sum of all the values from 2-6 not including 7 therefore 2+3+4+5+6 = 20 (please see pdf for code reference for each q) Q2: Which of the following inputs will result in the above method returning true? (There may be multiple correct answers. Select all of them.) a) 3 b) 5 ✓ c) 8 d) 14 ✓ e) 16 f) 28 because they are the only ones that are <16 initially, not %4 ==0 and then after they are *4 they are >16 so they fulfil all conditions [---------------------------------------------------------------------------------------] Q3: Which of the following types would be the most appropriate to represent the number of students enrolled at a university? (Select the single correct answer) a) boolean b) int ✓ c) char d) double because you cant have 1.5 of a person [---------------------------------------------------------------------------------------] Q4: What variables are in scope at the marked line? (There may be multiple correct answers. Select all of them.) a) a ✓ b) b ✓ c) c ✓ d) d e) e because anything that is in the foor loop is only in scope for the for loop the others are declared at the start [---------------------------------------------------------------------------------------] Q5: What is the largest value in x after running the above code? (Select the single correct answer) a) 12 b) 18 c) 22 d) 30 ✓ e) 60 f) None of the above start w array size 6 {0,1,2,3,4,5}, and you double the number in each position to fill it up: {0, 2, 4, 6, 8, 10}. Then, from the end of the array, you add each number to the number before it. By the time you reach the start of the array, each number has been added to the one before, making the first number the sum of all the others. The first number becomes the largest because it's the total of all additions. Therefore 2+4+6+8+10=30 [---------------------------------------------------------------------------------------] Q6: What is the type and value of the expression 7 + "10"? (Select the single correct answer) a) The string "17" b) The string "710" ✓ c) The integer 17 d) The integer 710 e) This expression causes a compile error because strings will make everything else strings when they concatenate [---------------------------------------------------------------------------------------] *** ok, the next one genuinely doesn't make sense because if you actually trace it will cause NullPointerExeption and not compile *** Q7:What does the above Java program print? (Select the single correct answer) a) 2 b) 3 c) 4 d) 5 ✓ e) 6 f) It does not compile successfully g) It throws an exception at runtime if we trace this correctly: 1. Mystery a = new Mystery(); creates a new Mystery object named a with count initialized to 0. 2. Mystery b = a; creates another reference b that points to the same Mystery object as a. At this point, a.count and b.count both reference the same count which is 0. 3. Mystery c = new Mystery(a, 3); invokes the constructor that increases a.count (and therefore b.count because a and b are references to the same object) by 3. Now, a.count and b.count are both 3. 4. Mystery d = new Mystery(b); effectively calls new Mystery(b, 1); because of the this(x, 1); call in the second constructor. This increases b.count by 1 (which is also a.count since a and b are still the same object). Now, a.count and b.count are both 4. 5. a = null; sets the reference a to null, but this doesn't affect the object itself. b is still referencing the original object with count 4. 6. a.count += 1; would throw a NullPointerException because a is now null. However, if we assume this line is not there, we can match the expected answer of 5. 7. The System.out.println(b.count); would print b.count, which is currently 4. But if we assume the increment from the non-existent line a.count += 1; then the count would be 5. But with the code as written, the correct answer is g) It throws an exception at runtime. [---------------------------------------------------------------------------------------] Question 8. (1 mark) Which of the following are reasons to not make a field public? (There may be multiple correct answers. Select all of them.) a) Correct - Encapsulation allows for flexible and maintainable code by keeping implementation details private, thus preventing external dependencies on how things work internally. c) Correct - Making a field non-public allows the class to control its own data, typically by providing methods that validate data before modifying the field, preventing invalid states. b) Incorrect - Access modifiers control visibility, not data encryption or security mechanisms like protection against malware. d) Incorrect - Memory usage of an object is determined by the data it stores, not by the access modifiers of its fields. All fields occupy memory space in an object, regardless of being public or private. [---------------------------------------------------------------------------------------] public class Mystery { private int counter = 0; public void tick() { counter++; } public int get() { return counter; } public static void main(String[] args) { Mystery.tick(); Mystery.tick(); System.out.println(Mystery.get()); } } Q9:What does the above Java program print? (Select the single correct answer) a) 0 b) 1 c) 2 d) The program does not compile ✓ e) The program throws a runtime error. Does not compile, Attempting to access a field on a null reference is invalid [---------------------------------------------------------------------------------------] Q10: Which of the following would be reasonable as an example of a subclass relationship? (There may be multiple correct answers. Select all of them.) a) Apple is a subclass of Fruit ✓ (it's a type of fruit) b) Vehicle is a subclass of Truck c) Aeroplane is a subclass of Vehicle ✓ (it's a type of vehicle) d) Apple is a subclass of Vehicle e) Wheel is a subclass of Truck (Goz said no, but in reality it's a type of part of a car so if the class was car_parts() then yes, but for this case no. The classes have to be able to be interchangeable a=b and b=a) [---------------------------------------------------------------------------------------] class Counter { protected int count = 0; public int get() { return count; } public void increment() { count += 1; } } class DoubleCounter extends Counter { public void increment() { count += 2; } } public class Mystery { public static void main(String[] args) { Counter counter = new DoubleCounter(); counter.increment(); counter.increment(); System.out.println(counter.get()); } } Q11: What does the above Java program print? (Select the single correct answer) ) 0 b) 1 c) 2 d) 3 e) 4 ✓ explanation: 1. Inheritance & Overriding: The DoubleCounter class inherits from Counter and overrides the increment() method to add 2 to the count instead of 1. 2. Polymorphism: An instance of DoubleCounter is created but referenced by a Counter type variable. Due to polymorphism, the overridden increment() method in DoubleCounter is used. 3. Execution: The increment() method is called twice on the DoubleCounter instance: Each call increases the count by 2. Two calls result in an increase of 2+2=4. 4. Output: The program prints the value of count, which is 4, after two increments. [---------------------------------------------------------------------------------------] class Shape { public boolean isShape() { return true; } } class Polygon extends Shape { public boolean hasSides() { return true; } } class Rectangle extends Polygon { public double angleDegrees() { return 90; } } class Hexagon extends Polygon { public int numSides() { return 6; } } class Square extends Rectangle { public double area(double length) { return length * length; } } Q12: Which of the following methods do objects of type Rectangle have? (There may be multiple correct answers. Select all of them.) a) isShape ✓ b) hasSides ✓ c) angleDegrees ✓ d) numSides e) area The numSides and area methods are not available to Rectangle objects as they are either in unrelated sibling classes or in subclasses. Hence, options d and e are incorrect for Rectangle. [---------------------------------------------------------------------------------------] Q13: Fill in the body of the following method such that it returns true if and only if num is between 1401 and 2005, inclusive. two most possible answers to this are public static boolean isInRange(int num) { return (1401 <= num && num <= 2005) ? true : false; } OR using if else was also valid [Goz said it was unessesary code, but if you did exactly as bellow then your answer is valid, will compile, uses return which was the main concern with the question and therefore you should get full marks for this, ask your lab facilitator that you're assigned to because they are most likely and usually the person who marks your test, ask for a review of your test + remark if you know you did it public static boolean isInRange(int num) { if (1401 <= num && num <= 2005) { return true; } else { return false; } } or this public static boolean isInRange(int num) { boolean isGreaterThanOrEqualTo1401 = num >= 1401; boolean isLessThanOrEqualTo2005 = num <= 2005; return isGreaterThanOrEqualTo1401 && isLessThanOrEqualTo2005; } FINALLY THIS COULD ALSO BE: (if you did python you would've been exposed to this) public static boolean isInRange(int num) { return switch (num) { case 1401, 1402, ..., 2005 -> true; default -> false; }; } [---------------------------------------------------------------------------------------] Question 14. (2 marks) Fill in the body of the following method such that it returns the sum of all the positive values in nums public static int sumOfPos(int[] nums) { int sum = 0; // Initialize sum to zero for (int num : nums) { // Loop through each element in the array if (num > 0) { // Check if the current element is positive sum += num; // Add positive elements to sum } } return sum; // Return the sum of all positive numbers } [---------------------------------------------------------------------------------------] Q15: Write a class called WeatherLog that represents a simple weather record for a particular day. It should have a maximum temperature in degrees Celsius, and rainfall in millimetres. There should be two constructors: One that sets both values, and one that sets only the temperature and assumes there was no rainfall that day. The measurements should only be accessible via getter methods. public class WeatherLog { private float maxTemp; // Store maximum temperature private int rainfall; // Store rainfall in millimeters // Constructor to initialize both max temperature and rainfall public WeatherLog(float maxTemp, int rainfall) { this.maxTemp = maxTemp; this.rainfall = rainfall; } // Overloaded constructor for when only max temperature is known public WeatherLog(float maxTemp) { this(maxTemp, 0); // Call the main constructor with 0 rainfall } // Getter for max temperature public float getMaxTemp() { return maxTemp; } // Getter for rainfall public int getRainfall() { return rainfall; } } [---------------------------------------------------------------------------------------] Q16:Write a class called Parcel that represents a parcel carried by a shipping company. It should have a length, width, and height measured in centimetres, and a weight measured in grams. There should be a constructor that sets all values. There should be a method getVolume() that returns the volume of the parcel in cubic centimetres. There should be a method getDensity() that returns the density of the parcel in grams per cubic centimetre. Hint: An example parcel might be 20 by 30 by 10 centimetres, with a weight of 1500 grams, and so have a volume of 6000 cubic centimetres and a density of 0.25 grams per cubic centimetre public class Parcel { private int length; // Length of the parcel in centimeters private int width; // Width of the parcel in centimeters private int height; // Height of the parcel in centimeters private int weight; // Weight of the parcel in grams // Constructor to initialize the parcel's dimensions and weight public Parcel(int length, int width, int height, int weight) { this.length = length; this.width = width; this.height = height; this.weight = weight; } // Method to calculate and return the volume of the parcel public int getVolume() { return length * width * height; } // Method to calculate and return the density of the parcel public float getDensity() { return (float) weight / getVolume(); } } I hope you can see or maybe put into perspective how the last few questions should be weighted at least 3-4 marks each as they have distinctive parts that make them whole. [----------------------------------[end of my rant]-------------------------------------]

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  5:07AM Sep 06 2023
Privacy policy