Question: Java: For my Tester, Please help me find a way to change the segment that asks Press any number to continue or -1 to stop:

Java: For my Tester, Please help me find a way to change the segment that asks"Press any number to continue or -1 to stop: " to "Do You wish to enter another score,(Enter y or n)" . Thanks:

Code in JAVA::

public class Student{

//InstanceVariables

/**Student name */

private String name;

/** Total of Quiz Scores */

private double totalScore;

/** Number of Quizzes Taken*/

private int quizCount;

/**

Constructs a student using default values.

*/

public Student()

{

name = "";

totalScore = 0;

quizCount = 0;

}

/**

Constructs a student with a given name.

@param n the name

*/

public Student(String n)

{

name = n;

totalScore = 0;

quizCount = 0;

}

/**

Sets the student name

@param aName the student's name

*/

public void setName(String aName)

{

name = aName;

}

/**

Gets the name of this student.

@return the name

*/

public String getName()

{

return name;

}

/**

Adds a quiz score.

Test score for valid score (0 >= score <= 100)

@param the score to add

*/

public void addQuiz(int score)

{

if(score >= 0 && score <= 100)

{

totalScore = totalScore + score;

quizCount = quizCount + 1;

}

else

{

System.out.println("Score must be between 0 and 100, inclusive");

}

}

/**

Gets the sum of all quiz scores.

@return the total score

*/

public double getTotalScore()

{

return totalScore;

}

/**

Gets the average of all quiz scores.

@return the average score

*/

public double getAverageScore()

{

return totalScore / quizCount;

}

}

MonitoredStudent.java

public class MonitoredStudent extends Student{ //InstanceVariables /*Minimum Average Grade required*/ private int minPassingAvg; /** * Default Constructor * */ public MonitoredStudent() { /* * INitializing Super Class i.e Student Class * constructor * */ super(); minPassingAvg=0; }

/** * Parameterized Constructor * */ public MonitoredStudent(int minPassingAvg) { super(); this.minPassingAvg = minPassingAvg; }

/** * @return the minPassingAvg */ public int getMinPassingAvg() { return minPassingAvg; }

/** * @param minPassingAvg the minPassingAvg to set */ public void setMinPassingAvg(int minPassingAvg) { this.minPassingAvg = minPassingAvg; } public boolean isOffProbation() { return this.getAverageScore()>=this.minPassingAvg; } }/*Class ends here*/

_________________________________________________________________________________________

MonitoredStudentTester.java ::

import java.util.Scanner;

public class MonitoredStudentTester {

public static void main(String[] args) throws Exception{ /** * Using Scanner class object named sc to take * input from user. * */ Scanner sc=new Scanner(System.in); /** * Asking User to enter name * */ String name; System.out.print("Enter your name : "); name=sc.nextLine(); /** * Asking to enter minimum passing average * */ int minimumPassingAverage; System.out.print("Enter minimum Passing Average : "); minimumPassingAverage=sc.nextInt(); /** * Creating object of Class MonitoredStudent named ms * And we pass the minimumPassingAverage as parameter * */ MonitoredStudent ms=new MonitoredStudent(minimumPassingAverage); /** * Setting name of the user to Student class * */ ms.setName(name); /** * Following while loop runs until user do not enter -1 to * stop taking the input i.e to break the loop * */ int score; while(true) { /** * Prompting user to enter quiz score * */ System.out.print(" Enter Quiz Score : "); score=sc.nextInt(); /** * Calling addQuiz() method and we pass the score as * parameter * */ ms.addQuiz(score); /** * Asking user to continue or to stop taing input * If user enters -1 then loop ends * */ int choice; System.out.print("Press any number to continue or -1 to stop : "); choice=sc.nextInt(); if(choice==-1) { break; } } System.out.println(" ________________Student Details________________"); System.out.println("Name :"+ms.getName()); System.out.printf("Total Score :%.2f ",ms.getTotalScore()); System.out.printf("Average Quiz Score :%.2f ",ms.getAverageScore()); if(ms.isOffProbation()) { System.out.println(" Congratulations!! You are off probation now."); }else { System.out.println(" Sorry! But you are still under probation."); } System.out.println("___________________________________________________"); }/*Main ends here*/ }/*Class ends here*/

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!