Practice Version Answers

  • Uploaded by: LeanneKraveFrancis
  • 0
  • 0
  • June 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Practice Version Answers as PDF for free.

More details

  • Words: 540
  • Pages: 3
Concepts Of Software Development In-Lab Assessment 4 Version D - Example Answers To complete this assessment you will have to first download the correct BlueJ project from the following web page. www.scism.lsbu.ac.uk/jfl/sd/csd06/ass4Practice.html All the following questions are related to the MarkList class. You will need to refer to the Mark class to understand how the MarkList class works.

field

1. The ArrayList called theList at line 11 is a 2. The list itself is actually created at line number 3. Lines 22 to 24 are an example of a

(1)

15

(1)

"loop" or "for loop"

(1)

4. What method is called in the Mark class at line 23 of the MarkList class? 5. In line 22, a) Mark is the name of a

Class

toString( )

but

b) mark is the name of a variable or reference variable 6. At line 39, the int total is a

local variable

(1)

(1) (1) (1)

7. At line 46 a calculation is made with the variable called count. In simple terms, what does count actually count? (1) Counts the number of marks in the list 8. The method displayFailCount() needs to be written. It should display something like The number of fails is 5, or whatever is the correct number of fails for this list of marks. When you have written the method in BlueJ and have got it working, write the code in the space below.

public class displayFailCount( ) { int count = 0; for ( Mark mark : theList){ if ( mark.hasFailed()){ count++; } } System.out.println("The number of fails is " + count); } (7)

MORE PRACTICE These exercises are designed to give you yet more practice at writing the program code described in chapter 4. It is more important that you have covered all of chapter 4 before you attempt these exercises. 1. Write a method that have displays the units that were passed ( i.e. Have not failed!). public void displayPassed() { for ( Mark mark : theList){ if ( ! mark.hasFailed()){ System.out.println( mark.getUnit()); } } } 2. Write a method that accepts a score and displays the units that score higher than the supplied score. public void displayHigher( int number) { System.out.println( "Units scoring higher than "+ number ); for ( Mark mark : theList){ if ( mark.getScore() > number){ System.out.println( mark.getUnit()); } } } 3. Write a method that displays the name of the unit with the highest score. public void displayHighest() { String highestUnit = "don't know"; int highestScore = -1; // got to be bigger than this for ( Mark mark : theList){ if ( mark.getScore() > highestScore){ highestScore = mark.getScore(); highestUnit = mark.getUnit(); } } System.out.println( "Highest scoring unit =" + highestScore ); }

4. Write a method that accepts a unit code as a String and looks through the list. If it finds the mark in the list with that unit code, it should display the score for that mark, otherwise it should say "not found" if it does not find the score.

public void findMark( String code) { boolean found = false; for ( Mark mark : theList){ if ( code.equals(mark.getUnit())){ //!!! System.out.println( mark); found = true; } } if( ! found) { System.out.println( "unit not found"); } }

Related Documents


More Documents from ""