IT 168 Fall 2020
Program 4
Due Date:
Problem:
A simulation program is needed to determine if the ISU Quiz Bowl Team should comprise mainly of genius students or regular students.
A primary requirement of this program that is different from your earlier assignments is that you are required to create 2 different Java classes in the design of your program. Here are some other design details that may be helpful:
Design:
The classes should be placed in a package with the name edu.ilstu
The all classes should have proper Javadoc comments
Student class
Keeps track of the brain power a student on the Quiz Bowl Team. This class should include the following:
QuizBowl class
This is the starting point for the application which is the only class to contain a main method. You will use the Student class here. For this program, the main method handles all of the input and output for the program and will perform the following tasks:
I am working on the above assignment for my introductory Java class. I've created the methods, getters and required constructor but am now struggling with how to format the parameters and what kind of loops to use and how to format them. I am at my whit's end with this program and could use some assistance
File: Student.java
package edu.ilstu;
import java.util.Random;
public class Student {
private String studentName;
private char studentType;
private float currentBrainPower;
private int currentScore;
public Student(char type, String name) {
studentName = name;
studentType = type;
if(type=='g') {
currentBrainPower = 50;
}
else {
currentBrainPower = 30;
}
currentScore = 0;
}
public String getStudentName() {
return studentName;
}
public char getStudentType() {
return studentType;
}
public float getCurrentBrainPower() {
return currentBrainPower;
}
public int getCurrentScore() {
return currentScore;
}
public void study(int time) {
if(studentType=='g')
currentBrainPower = currentBrainPower * 2 * time;
else if(studentType=='r')
currentBrainPower = currentBrainPower * 0.75F * time;
}
public int answerQuestion(int answer) {
Random rand = new Random();
if(studentType=='r') {
currentBrainPower -= 5;
return rand.nextInt(100)+1;
}
else {
currentBrainPower -= 3;
return answer-15+rand.nextInt(31);
}
}
public void creditForBestAnswer() {
currentScore += 1;
}
}
File: QuizBowl.java
package edu.ilstu;
import java.util.Random;
public class QuizBowl {
public static void main(String[] args) {
Random rand = new Random();
Student studA = new Student('g', "StudentA");
Student studB = new Student('r', "StudentB");
studA.study(2);
studB.study(6);
while (studA.getCurrentBrainPower() != 0 && studB.getCurrentBrainPower() != 0 && studA.getCurrentBrainPower() != 10
&& studB.getCurrentBrainPower() != 10) {
int answer = rand.nextInt(100) + 1;
int ansA = studA.answerQuestion(answer);
int ansB = studB.answerQuestion(answer);
if (Math.abs(answer - ansA) < Math.abs(answer - ansB)) {
studA.creditForBestAnswer();
}
else {
studB.creditForBestAnswer();
}
}
Student winner = null, loser = null;
if(studA.getCurrentScore() > studB.getCurrentScore()) {
winner = studA;
loser = studB;
}
else {
winner = studB;
loser = studA;
}
System.out.println("\nWinner:");
System.out.println("Name: "+winner.getStudentName());
System.out.println("Type: "+winner.getStudentType());
System.out.println("Score: "+winner.getCurrentScore());
System.out.println("Current brain power: "+winner.getCurrentBrainPower());
System.out.println("\nLoser:");
System.out.println("Name: "+loser.getStudentName());
System.out.println("Type: "+loser.getStudentType());
System.out.println("Score: "+loser.getCurrentScore());
System.out.println("Current brain power: "+loser.getCurrentBrainPower());
}
}
Output:
Get Answers For Free
Most questions answered within 1 hours.