It is most beneficial to you to write this mock midterm UNDER EXAM CONDITIONS. This means: Complete the Exam in 3 hour(s). Work on your own. Keep your notes and textbook closed. Attempt every question. After the time limit, go back over your work with a different colour or on a separate piece of paper and try to do the questions you are unsure of. Record your ideas in the margins to remind yourself of what you were thinking when you take it up at PASS. The purpose of this mock exam is to give you practice answering questions in a timed setting and to help you to gauge which aspects of the course content you know well and which are in need of further development and review. Use this mock exam as a learning tool in preparing for the actual exam. Please note: Come to the PASS workshop with your mock exam complete. During the workshop you can work with other students to review your work. Often, there is not enough time to review the entire exam in the PASS workshop. Decide which questions you most want to review the Facilitator may ask students to vote on which questions they want to discuss in detail. Facilitators do not bring copies of the mock exam to the session. Please print out and complete the exam before you attend. Facilitators do not produce or distribute an answer key for mock exams. Facilitators help students to work together to compare and assess the answers they have. If you are not able to attend the PASS workshop, you can work alone or with others in the class. Good Luck writing the Mock Exam!! Dates and locations of mock exam take-up: December 15 th, 2017. Location: ME3275
Question 1: Concepts Answer the following questions: 1) Define: Objects, classes 2) What method is responsible for initializing objects? 3) What is unique about an Abstract class? 4) What libraries do we need to import to implement ArrayLists and Random numbers? 5) List 5 classes of GUI
Question 2 In this question, you are going to develop a class called Pl ayer that will be used to collect players into a team using arrays a) This class will use the Rando m class in Java. Write the required code to access the class b) Our class will have five fields: MAX: the maximum size of our collections: a constant to be set to 20 ar : an array of integers curr Max: the current maximum size of our collections (not a constant) count : the current size of the array Define the instance variables:
c) SYSC 2004 Our class has one constructor. This constructor has no parameters. It sets curr Max to a random number between1 and MAX, using a Rando mobject. The array contains a maximum of currma x items. Write the constructor. Javadoc comments are required for full marks public Player()
d) SYSC 2004 Write method addpl ayer which takes a String parameter and returns a boolean. If there is space in the array, the method adds the player to the array, after any other players already present, and returns true. Otherwise, the method returns false. Javadoc comments are required for full marks. e) What changes are required if we insert the String value before any other values already present in the array? Do not re-write the entire method, just modify the code to satisfy the new requirement and explain what it has replaced
f) Write a method call fi ndspecficpl ayer which has a String parameter and returns a boolean. It is to search the array for the given parameter and return true if there is at least one copy in the array, and false otherwise. Javadoc comments are required for full marks. You must use a "for" loop for full marks.
g) SYSC 2004 Write a method call pri nt All Pl ayers which prints all the players in the array. You may use a "for each or a foor loop. Javadoc comments are required for full marks. Question 3 - Inheritance In this question, you are going to develop a subclass class called Bus. Bus is a subclass of class Vehi cl e. Below is the code provided for class Vehi cle and you are required to write the code for the Bus class
public class Vehicles SYSC 2004 private String name; // name of the car private String comp; // the company that manufactured the car private int stock; // number of cars in stock /** * Constructor for objects of class Vehicle * Takes three parameters and sets the * fields based on the parameters entered. * you have to fill in the parameters * Public Vehicle(String name, String comp,int stock ) this.name=name; this.comp=comp; this.stock=stock; /** * getname() returns the name of the Vehicle * * public String getname() return name; /** * getcomp() returns the company the Vehicle was manufactured by public String getcomp() return comp;
/** * getstock() returns the number of Vehicle in stock public int getstock() return stock; /** * addstock() increments the stock of the Vehicle by 1 public void addstock() stock++; /** * removestock() decrements the stock by 1. The stock cannot go below 0. * If the method succeeds in decrementing the stock, it returns true. * If it does not (i.e. stock was already 0) it returns false. * * public boolean removestock() if( stock>=1) stock--; return true; return false; Complete class Bus below: - Write a constructor for class Bus that takes in name, the manufacturer, the stock and the Price. - Write a method that returns the name of the bus - Write a method that returns the stock of the bus - Write a method that adds to the stock of the bus - Write a method removes the stock of the bus - Write a method that returns the price of the stock
public class Bus SYSC 2004 //methods and constructors are omitted
)// end of Class Question 4 UML Diagram In this question, you are going to draw a UML diagram of the Vehicle class and its subclass. Question 5 Test Cases for Bus Class In this question you are going to write test cases for the Bus class, testbus. When answering this question, you are not permitted to add fields, constructors or methods to class Bus. Returns false if the name of the bus is Null The stock of the bus equals 2
The price of the bus equals 3500 Returns Ture if the manufacturer of the bus is TATA Returns false if the name of the bus Civic Public Class testbus
SYSC 2004 Question 6 GUI In this question, you are going to implement a simple GUI. The GUI models a Counter class that was displayed in class. public class CounterController extends JFrame implements ActionListener a) Complete the omitted code //The button that is clicked to increment the counter. //The button that is clicked to decrement the counter. // The button that is clicked to reset the counter to 0. // declare a variable that is of type CounterModel b// create a button panel, add all three button to the panel, // adjust the panel to be located at the centre
c)// register the frame as a listener for the buttons d) // implement the action performed method that will be called when the user clicks on GUI buttons
Reference for Question 6: import java.util.observable; /** * A CounterModel models an up/down integer counter whose value is always >= 0. * Instances of this class can be observed by one or more observers (see * java.util.observer & java.util.observable); these observers are notified
* every time the counter's state changes. SYSC 2004 * * @author D.L. Bailey, Department of Systems and Computer Engineering, * Carleton University. * @version 1.00 March 22, 2005. public class CounterModel extends Observable /** The current value of the counter. private int count; public CounterModel() count = 0; /** Increments the counter by 1. public void increment() count++; setchanged(); notifyobservers();
/** SYSC 2004 * Decrements the counter by 1. Ensures that the counter never * becomes negative. public void decrement() if (count > 0) count--; setchanged(); notifyobservers(); /** Resets the counter to 0. public void reset() count = 0; setchanged(); notifyobservers(); /** * Returns the value stored in this counter.
* @return the current counter value. SYSC 2004 public int value() return count; /** * Returns a String representation of this counter, * @return a String containing the current counter value. public String tostring() return Integer.toString(count);