Continued 19 the exammark class is defined as follows

This preview shows page 18 - 22 out of 28 pages.

CONTINUED 19. The ExamMark class is defined as follows: public class ExamMark { private int mark; public ExamMark(int examMark) { mark = examMark; } public int getMark() { return mark; } public void setMark(int examMark) { mark = examMark; } public boolean getHasPassed() { return mark >= 50; } public String toString() { String markInfo = ""; markInfo = markInfo + "Exam mark: " + mark + "%"; if (getHasPassed()) { markInfo = markInfo + " " + " A PASS"; } else { markInfo = markInfo + " " + " NOT A PASS"; } return markInfo; } } Answer the following questions (a) – (g) which refer to the ExamMark class. a) Write a Java statement which declares an array of ExamMark objects. Call the array marks , i.e. use the identifier marks for the array variable.
Image of page 18

Subscribe to view the full document.

VERSION 18832768 - 19 - COMPSCI 101 Question and Answer Booklet ID .......................................... CONTINUED b) Write a Java statement which initialises the marks array (that you declared in part (a) above) to be large enough to store exactly 500 ExamMark objects. c) Write a Java statement which stores the object, goodMark , in index position 0 of the marks array. The goodMark variable has been declared and initialised for you. ExamMark goodMark = new ExamMark(96); For parts d) to g) below, assume that the marks array has been created and contains some ExamMark objects. d) Complete the Java statement below which assigns the ExamMark object in index position 2 of the marks array to the variable, markEric . ExamMark markEric = e) Complete the Java statement below which obtains the mark of the ExamMark object in index position 5 of the marks array, and stores it in the variable aMark . int aMark =
Image of page 19
VERSION 18832768 - 20 - COMPSCI 101 Question and Answer Booklet ID .......................................... CONTINUED f) Complete the single Java statement below which assigns true to the variable hasPassed if the ExamMark object in index position 12 of the marks array is a pass mark and assigns false otherwise. boolean hasPassed = g) Complete the countNumberPassed() method below which processes the marks array and returns the number of elements of the marks array which are pass marks. Note: the number of ExamMark objects in the marks array is given by the parameter, numberOfMarks . private int countNumberPassed(ExamMark[] marks,int numberOfMarks){ int numberPassed = 0; return numberPassed; } (10 marks)
Image of page 20

Subscribe to view the full document.

VERSION 18832768 - 21 - COMPSCI 101 Question and Answer Booklet ID .......................................... CONTINUED 20. For this question, you need to complete the definition of the Square class. The following program displays two small squares which are animated and move from side to side along the top boundary of the window. Initially, both squares start with their top left hand corners at position (0, 0), and they both are 20 pixels wide and 20 pixels high. As the program runs, both squares start moving horizontally towards the right ( the small arrows in the diagram are shown to represent the direction of movement and are NOT part of the output ), however they do not travel at the same speed.
Image of page 21
Image of page 22
You've reached the end of this preview.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern