17 question 6 method setpredictedresult 4 marks

This preview shows 17 out of 20 pages.

17 Question 6 // METHOD setPredictedResult: (4 marks) // Method parameters: a double that is the predicted result // of the experiment. // RESULT: none Question 6 // METHOD setPredictedResult: (4 marks) // Method parameters: a double that is the predicted result // of the experiment. // RESULT: none public static void setPredictedResult( doublenewPrediction ) { prediction = newPrediction; }
Image of page 17

Subscribe to view the full document.

18 Question 6 // MODIFIER METHOD addTrial: (6 marks) // Method parameters: a Trial object that should be added to the Experiment. // Results: will print a message if the experiment has no room to store // additional trials (see sample output for message format) // Modified: the Experiment object Question 6 // MODIFIER METHOD addTrial: (6 marks) // Method parameters: a Trial object that should be added to the Experiment. // Results: will print a message if the experiment has no room to store // additional trials (see sample output for message format) // Modified: the Experiment object public void addTrial( Trial newTrial ) { if ( numTrials >= trials.length ) { System.out.println("No more trials can be added to the experiment."); } else { trials[numTrials] = newTrial; numTrials = numTrials + 1; } }
Image of page 18
19 Question 6 // METHOD print: (6 marks) // Method parameters: (none) // Returns: (none) // This method prints the result and duration of each trial, along with // the absolute value of the difference from the predicted result. // See the TestExperiment sample output for exact format. Question 6 // METHOD print: (6 marks) // Method parameters: (none) // Returns: (none) // This method prints the result and duration of each trial, along with // the absolute value of the difference from the predicted result. // See the TestExperiment sample output for exact format. public void print( Trial newTrial ) { int index; double aResult; double difference; for ( index = 0; index < numTrials; index = index + 1 ) { aResult trials[index].getResult(); difference = Math.abs( aResult – prediction ); System.out.print("Trial " + index + ": " ); System.out.print("Result " + aResult + ", " ); System.out.print("Duration " + trials[index].getDuration() + ", " ); System.out.println("(within " + difference + " of prediction)" ); } }
Image of page 19

Subscribe to view the full document.

20 Question 7 [10] Binary search – to be discussed in lecture
Image of page 20
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