It's UWAweek 26 (mid-year break)

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 the 5 articles in this topic
Showing 5 of 257 articles.
Currently 8 other people 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]-------------------------------------]


SVG not supported

Login to reply

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

ANONYMOUS wrote:
> 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 an 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]-------------------------------------]


SVG not supported

Login to reply

👍?
helpful
8:49pm Tue 23rd Apr, Tin CP.

*** 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)

I think you may be mistaken - Q7 will not result in a NullPointerException, because the line a = null; is AFTER a.count += 1;. In your steps, you stated that a is assigned null BEFORE it is incremented whereas the code in the actual paper had the null assignment AFTER incrementing a. Perhaps the code provided in the class had it the other way around?

Also disclaimer, I'm just one of the facilitators who's interested in the feedback - could I ask for clarification on your concerns regarding the MCQs? Specifically, what are the sources of confusion and reasons that it's poorly implemented? Your feedback only stated that the questions are "poorly implemented", "vague", and not done "properly", without stating the actual reasons or how the questions may be ambiguous (or I may have missed them). As such, it's unclear what problem your suggested solution of multiple-value questions seeks to address.

I understand it's much more time-consuming as students have to check every single option, though this significantly reduces the risk of guessing as the likelihood of a student guessing the right number of options, AND the right option(s) is much smaller than just guessing a single option. It better assesses students' understanding by asking them to critically evaluate every option, whereas having multiple values per option has the same likelihood as any single-answer questions AND may take just as long to evaluate as multiple-answer questions. Again, it'll be greatly appreciated if you could elaborate on specific issues with the current approach.

Ah also, your explanation of each question is very in-depth, thank you for making it available for other students to learn from!


SVG not supported

Login to reply

👍?
helpful
9:00pm Tue 23rd Apr, Tin CP.

ask your lab facilitator that you're assigned to because they are most likely and usually the person who marks your test

This may be the case for some units, but no - the tests are not allocated based on who the student's lab facilitator is.

Otherwise yes, please point out any mistakes in marking or areas needing clarification, we make mistakes too so it's highly encouraged for students to check their marked submissions!


SVG not supported

Login to reply

👍?
helpful
12:49pm Wed 24th Apr, Andrew G.

While your notes are mostly correct, they do contain a number of errors. I am probably not going to be able to address them all here, but I have already explained the answers in a lecture and a PDF of the answers is available on LMS under the Mid-Semester Test Info page. I will the ones I can pick out, though, in an effort to prevent this causing yourself and other students future misunderstandings.
> 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
I assume this is referring to Question 2, as I can see no reason to trace any other question multiple times. There is no need to trace every option, as you can analyse the code to reason about what properties an input must have to return true, which then allows you to pick the answer easily. Even if you do not make this observation, the method in question is three if statements in sequence, and should not take the typical student more than a few seconds to trace. This was specifically chosen so as to allow tracing as a method in the available time. Question 2 should certainly not be taking you 4-5 minutes.
> *** 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.
Your tracing is incorrect. You have swapped the lines `a = null;` and `a.count += 1;`. If in doubt you can attempt to compile and run the code, it is a complete Java source file:
> javac Mystery.java > java Mystery
5 Which gives 5, as expected. I was careful to test the code used in the mid-sem ahead of time to make sure it did not contain any typos or other minor errors that could lead to confusion.
> 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
You are correct that it does not compile, but your reasoning is incorrect. There is no null reference in this code to attempt to access a member from. This code does not compile because `Mystery` is a class and hence `Mystery.tick()` is an attempt to call a static method on that class, but no such static method exists, as `tick()` is non-static. To call `tick()`, one would first have to construct an instance of a `Mystery` object, and then call the `tick()` method on that object.
> 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)
I am not sure what you mean by a class `car_parts()`. If you mean to propose the existence of a class, let's say `CarPart` that represents any part of a car, then yes, it would be plausible that `Wheel` is a subclass of `CarPart`. But the question asks for whether Wheel is a subclass of Truck. Recall that the property of a subclass is that it inherits properties from its parent class, and so can be used anywhere its parent could be. As you put it, A is a subclass of B if A is a *type* of B. So Wheel is not a subclass of Truck, as a wheel does not have all the properties of a Truck, and cannot be used as a Truck. You also say that "the classes have to be able to be interchangeable a=b and b=a". This is not correct. There is no requirement for the superclass to be able to be substituted for the subclass. The subclass (Apple, for example) may have properties its superclass (Fruit) does not, and so logic that works with Apples may not be able to work with Fruits, as it may depend specifically on the properties of Apple, which Fruit may not have. The other way around is fine because if Apple is a subclass of Fruit then we know it has inherited all its properties, and so any logic that works with Fruits could work with Apples.
> 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; > }
These are all valid answers that would receive full marks, despite being unnecessarily over-complicated, because no marks were awarded for simplicity. So long as you wrote valid Java that implemented the correct logic, you are guaranteed both marks. However, there is a simpler answer (that I gave in the sample answers) that you have omitted: public static boolean isInRange(int num) { return 1401 <= num && num <= 2005; } There is no need to use the ternary expression, as the condition you are using is already the desired result.
> 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; > }; > }
Recall that in this unit we use the (admittedly older) Java 11. The code you have given is not valid Java 11. Your code appears to use a feature introduced in Java 12 (JEP 354), but the `...` is not valid syntax. If you mean to indicate that you could write out the full list of integers from 1401 to 2005, that would be valid Java 12 and would give the correct answer, but I would advise students not to attempt to write a list of 605 four digit numbers in the time available in a mid-sem. If someone did do that in the test, I would probably be lenient and award the marks, despite the fact that we only officially cover features that exist in Java 11.
> 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.
Questions are not necessarily weighted by difficulty. If you are able to do the more difficult problems, you are already solving more problems than those who can only do the easier ones. Each of the written questions is designed to assess your working understanding of how to do different things in Java. Each question builds upon the previous. To get the marks for Question 13 you only need to construct and return a simple expression. To get the marks for Question 14 you must now introduce control structures such as loops and if statements, while working with arrays. To get the marks for Question 15 you only need to produce an extremely simple class that just stores two fields and does no logic with them. To get the marks for Question 16 you must now demonstrate doing simple computations with the fields of a class. The different capabilities being assessed in each question are not so challenging as to be deserving of more marks.
> [----------------------------------[end of my rant]-------------------------------------]
Your notes for most of the questions were well done. I hope the above helps with the mistakes that were present. I will end with a reminder that the mid-semester test is a formative assessment, where the goal is to highlight what material students are comfortable with and what material they may have misunderstood and need to revise. I encourage all students to explore the questions where they lost marks in greater detail and attempt to reinforce their understanding of the concepts at play in those questions. For those students who got full marks, this hopefully indicates you have a good broad understanding of the material we have covered so far in this unit, though it is of course impossible to assess everything in a single test.

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