Question

Within DrJava, create a class called StudentQuizScores and do the following using a do-while loop. 1....

Within DrJava, create a class called StudentQuizScores and do the following using a do-while loop.

1. You program will read in a student’s first name. The same will be done for the student’s last name. Your program will use respective methods (described below) to accomplish this.

2. Your program will then read in three quiz scores, respectively. This should be done by using the same method three times. This method is described below.

3. Your program will then calculate the average of these three quiz scores. This will be obtained from a method described below.

4. A string will be built that will have information about the student (the student name, the three quiz scores, and the average for these quiz scores). This string will be built within a particular method described below.

5. In the main method, your program should print this string to the console using a Scanner object (keyboard).

6. Your program should then generate a number between 1 and 3 (this can be done within the main method). Your program should use the Random object (randomNumbers) in the following manner: changeScore = randomNumbers.nextInt(3) + 1; Where changeScore is a variable that was declared in the main method. Using the newly generated number, determine which quiz score should be changed (you may use a switch statement or a series of if-else statements to determine this). Then call upon the proper method described below.

7. Again, your program will then calculate the average of these three quiz scores. This will be obtained from a method.

8. Again, a string will be built that will have information about the student (the student name, the three quiz scores, and the average for these quiz scores). This string will be built within a particular method described below.

9. Again, in the main method, your program should print this string to the console using a Scanner object (keyboard).

10.Finally, use a method to prompt the user to see if they wish to exit the program. Use the returned value from this method to determine whether your program should exit.

11.If the user does not want to exit the program, then repeat steps 1 through 10 for another student.

12.If the user does want to exit the program, then print out to the console “This program was written by ” and “End of program.” Both of these strings should be printed on separate lines.

13.Appropriate comments must be used in this program where applicable.

No prompting should be done within the main method. Rather they should be done within any respective method. Here are the methods that your program must use in your program.

All methods must be preceded by the keywords public static :

• String getFirstName() no parameters are received; will prompt the user for the student’s first name and then return the student's first name

• String getLastName() no parameters are received; will prompt the user for the student’s last name and then will return the student's last name

• int getScore() no parameters are received; will prompt the user for a student’s quiz score and then will return the quiz score (between the value of 0 and 100) • double getScoreAverage(int s1, int s2, int s3) will receive three integer parameters; will return the average of the three quiz scores

• String buildString(String fName, String lName, int s1, int s2, int s3, double avg) will receive six parameters; will return a string that will be built from these six parameters

• boolean exitProgram() no parameters are received; will return either the boolean value true or the boolean false depending on whether the user wants to exit the program

Note: in this method after you prompt the user and before you read in from the keyboard you should insert the following line: keyboard.nextLine(); This will pick up the leftover newline character that was left over from reading in the quiz scores.

• int newScore(int changeScore, int score) will receive two parameters (first parameter will determine which quiz score needs to be changed, the second parameter will be quiz score that will be changed); the new quiz score will be returned

A. Make sure that you import the classes Scanner and Random respectively, into your program For the Scanner object (call it keyboard) declare it as a class variable. Declare it above and outside the main method but still within the class.

It should look something like the following: public static Scanner keyboard = new Scanner (System.in);

For the Random object (call it randomNumbers), it should be declared within the main method and should look something like the following:

Random randomNumbers = new Random();

B. Do not forget to prompt the user where appropriate

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Random;
import java.util.Scanner;

public class QuizScoreSimulator {
  
private static Scanner keyboard;
  
public static void main(String[] args)
{
boolean yesNo;
do
{
String firstName = getFirstName();
String lastName = getLastName();
  
System.out.println("Enter score for 3 quizes:\n-------------------------");
int score1 = getScore();
int score2 = getScore();
int score3 = getScore();

double averageScore = getScoreAverage(score1, score2, score3);

System.out.println("\n" + buildString(firstName, lastName, score1, score2, score3, averageScore));

Random randomNumbers = new Random();
int changeScore;
do
{
changeScore = randomNumbers.nextInt(3) + 1;
}while(changeScore < 1 || changeScore > 3);

System.out.print("\nSystem randomly chose Quiz " + changeScore + " Score to change.\n"
+ "Enter the new score for Quiz " + changeScore + ": ");
int newScore = keyboard.nextInt();
switch(changeScore)
{
case 1:
score1 = newScore(changeScore, newScore);
averageScore = getScoreAverage(score1, score2, score3);
System.out.println("\nAfter changing Quiz 1 Score:\n" +
buildString(firstName, lastName, score1, score2, score3, averageScore));
break;

case 2:
score2 = newScore(changeScore, newScore);
averageScore = getScoreAverage(score1, score2, score3);
System.out.println("\nAfter changing Quiz 2 Score: \n" +
buildString(firstName, lastName, score1, score2, score3, averageScore));
break;

case 3:
score3 = newScore(changeScore, newScore);
averageScore = getScoreAverage(score1, score2, score3);
System.out.println("\nAfter changing Quiz 3 Score: \n" +
buildString(firstName, lastName, score1, score2, score3, averageScore));
break;
}
System.out.println();
yesNo = exitProgram();
System.out.println();
}while(!yesNo);
}
  
public static String getFirstName()
{
keyboard = new Scanner(System.in);
System.out.print("Enter student's first name: ");
String firstName = keyboard.nextLine();
return firstName;
}
  
public static String getLastName()
{
keyboard = new Scanner(System.in);
System.out.print("Enter student's last name: ");
String lastName = keyboard.nextLine();
return lastName;
}
  
public static int getScore()
{
keyboard = new Scanner(System.in);
int score = 0;
do
{
System.out.print("Enter quiz score: ");
score = keyboard.nextInt();
}while(score < 0 || score > 100);
return score;
}
  
public static double getScoreAverage(int s1, int s2, int s3)
{
return (double)(s1 + s2 + s3) / 3;
}
  
public static String buildString(String fName, String lName, int s1, int s2, int s3, double avg)
{
return ("First Name: " + fName + "\nLast Name: " + lName + "\nQuiz 1 Score: " + s1
+ "\nQuiz 2 Score: " + s2 + "\nQuiz 3 Score: " + s3
+ "\nAverage Score: " + String.format("%.2f", avg) + "\n");
}
  
public static boolean exitProgram()
{
System.out.print("Exit program? [y/n]: ");
keyboard.nextLine();
char yesNo = keyboard.nextLine().toLowerCase().charAt(0);
return yesNo == 'y';
}
  
public static int newScore(int changeScore, int score)
{
changeScore = score;
return changeScore;
}
}

************************************************************** SCREENSHOT *************************************************************

Add a comment
Know the answer?
Add Answer to:
Within DrJava, create a class called StudentQuizScores and do the following using a do-while loop. 1....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a class called Student. The specification for a Student is: Three Instance fields name -...

    Write a class called Student. The specification for a Student is: Three Instance fields name - a String of the student's full name totalQuizScore - double numQuizesTaken - int Constructor Default construtor that sets the instance fields to a default value Parameterized constructor that sets the name instance field to a parameter value and set the other instance fields to a default value. Methods setName - sets or changes the student name by taking in a parameter getName - returns...

  • Assignment W3-2 This programming assignment addresses: •Compiling and Executing an App with more than 1 class...

    Assignment W3-2 This programming assignment addresses: •Compiling and Executing an App with more than 1 class •Initializing Objects using Constructors •Software Engineering with Private Instances Variables and Public Set/Get Methods •Uses Methods inside classes Description: You are asked to write a program to process two students’ scores. Each student will have scores for 3 tests, the user will input each student’s full name followed by their three scores. When the data for the two students are read from the keyboard,...

  • Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class...

    Create a class named Module2. You should submit your source code file (Module2.java). The Module2 class should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) Data fields: A String object named firstName A String object named middleName A String object name lastName Methods: A Module2 constructor method that accepts no parameters and initializes the data fields from 1) to empty Strings (e.g., firstName =...

  • Complete the following Java class. In this class, inside the main() method, user first enters the...

    Complete the following Java class. In this class, inside the main() method, user first enters the name of the students in a while loop. Then, in an enhanced for loop, and by using the method getScores(), user enters the grades of each student. Finally, the list of the students and their final scores will be printed out using a for loop. Using the comments provided, complete the code in methods finalScore(), minimum(), and sum(). import java.util.Scanner; import java.util.ArrayList; public class...

  • Create a java class for an object called Student which contains the following private attributes: a...

    Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

  • import java.util.Scanner; // TASK #1 Add the file I/O import statement here /** This class reads...

    import java.util.Scanner; // TASK #1 Add the file I/O import statement here /** This class reads numbers from a file, calculates the mean and standard deviation, and writes the results to a file. */ public class StatsDemo { // TASK #1 Add the throws clause public static void main(String[] args) { double sum = 0; // The sum of the numbers int count = 0; // The number of numbers added double mean = 0; // The average of the...

  • c++ Instructions Overview In this programming challenge you will create a program to handle student test...

    c++ Instructions Overview In this programming challenge you will create a program to handle student test scores.  You will have three tasks to complete in this challenge. Instructions Task 1 Write a program that allocates an array large enough to hold 5 student test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the...

  • read the code and comments, and fix the program by INSERTING the missing code in Java...

    read the code and comments, and fix the program by INSERTING the missing code in Java THank you please import java.util.Scanner; public class ExtractNames { // Extract (and print to standard output) the first and last names in "Last, First" (read from standard input). public static void main(String[] args) { // Set up a Scanner object for reading input from the user (keyboard). Scanner scan = new Scanner (System.in); // Read a full name from the user as "Last, First"....

  • package _solution; /** This program demonstrates how numeric types and operators behave in Java Do Task...

    package _solution; /** This program demonstrates how numeric types and operators behave in Java Do Task #1 before adding Task#2 where indicated. */ public class NumericTypesOriginal { public static void main (String [] args) { //TASK #2 Create a Scanner object here //identifier declarations final int NUMBER = 2 ; // number of scores int score1 = 100; // first test score int score2 = 95; // second test score final int BOILING_IN_F = 212; // boiling temperature double fToC;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT