Question

IT 168                                         &nb

IT 168                                                                                          Fall 2020

Program 4

Due Date:

  • October 21 at 11:55 PM

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:

  • Instance Variables
    • studentName
    • studentType
    • currentBrainPower
    • currentScore
  • Methods
    • Getters for each instance variable
    • A method, void study(int time), which increases the student’s currentBrainPower. A genius student (i.e. studentType == ‘g’) increases their currentBrainPower at the rate of 2 times each time unit. A regular student (i.e. studentType == ‘r’) increases their currentBrainPower at the rate of .75 times each time unit.
    • A method, int answerQuestion(int answer) that will calculate the student’s answer to the Quiz Bowl Simulator question. A regular student answers the question by generating a random number between 1 and 100, costing the student a loss of brain power of 5 points. A genius student answers the question by generating random numbers until they get a random number that is within plus or minus 15 of the answer passed in. For each random number that a genius student generates while trying to get within plus or minus 15 points of the answer, they suffer a brain power loss of 3 points.
  • A method, void creditForBestAnswer(), that will add 1 to the student’s currentScore.
  • A constructor Student(char type, String name) which initializes the student object using the two parameters for studentName and studentType. Genius students start with a currentBrianPower of 50 and regular students start with a currentBrainPower of 30,

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:

  • Create two instances of the Student class, with one student being a genius and one being a regular student.  
  • Have the genius student study for 2 hours.
  • Have the regular student study for 6 hours.
  • Loop until either one of the students runs out of brain power (i.e. currentBrainPower == 0) or one of the students reaches a score of 10 (i.e. currentScore == 10)
    • Generate the answer (i.e. a random number between 1 and 100)
    • Ask the regular student for their answer
    • Ask the genius student for their answer
    • Determine which student’s answer was closest to the answer
      • For the student whose answer was closest to the answer, give them credit for having the best answer.
  • Display the winner’s name, type, score, and current brain power.
  • Display the loser’s name, type, score, and current brain power.

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

Homework Answers

Answer #1

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:

Know the answer?
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
Similar Questions
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class...
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class called Student which implements Duty. Class Student adds 1 data field, id, and 2 methods, getId and setId, along with a 1-argument constructor. The duty of a Student is to study 40 hours a week. b. Write a class called Professor which implements Duty. Class Professor adds 1 data field, name, and 2 methods, getName and setName, along with a 1-argument constructor. The duty...
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you...
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you start doing anything… This project involves implementing a simple university personnel management program. The program contains two different kinds of objects: students and faculty. For each object, the program stores relevant information such as university ID, name, etc. Different information is stored depending on the type of the object. For example, a student has a GPA, while a faculty has a title and department...
(The Rectangle class) (WOULD APPRECIATE IT IF THE PROGRAM/ANSWER COULD BE DIRECTLY COPY AND PASTED, also...
(The Rectangle class) (WOULD APPRECIATE IT IF THE PROGRAM/ANSWER COULD BE DIRECTLY COPY AND PASTED, also this should be in java) Following the example of the Circle class in Section 9.2, design a class named Rectangle to represent a rectangle. The class contains: - Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. - A no-arg constructor that creates a default rectangle....
c++ C++ CLASSES and objects DO ADD COMMENTS DISPLAY OUTPUT First make three files: episode.cpp, episode.h...
c++ C++ CLASSES and objects DO ADD COMMENTS DISPLAY OUTPUT First make three files: episode.cpp, episode.h andRun.cpp to separate class header and implementation. In this program, we are going to create a small scale Telivision Management System. A) Create a class Episode with following variables: char* episode_name, char* episode_venue, char episode_date[22] and char episode_time[18]. Input format for episode_date: dd-mm-yyyy Input format for episode_time: hh:mm am/pm B) Implement default constructor and overloaded constructor. Print “Default Constructor Called” and “Overloaded Constructor Called”...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName (a String), numSold (an integer that represents the number of that type of game sold), and priceEach (a double that is the price of each of that type of Game). I only want three instance variables!! The class should have the following methods: A constructor that has two parameter – a String containing the name of the Game and a double containing its price....
JAVA QUIZ Question 1 Which of the following is false about a "super" call in a...
JAVA QUIZ Question 1 Which of the following is false about a "super" call in a sub class's constructor? Select one: a. It must be the first statement in the constructor b. If you don't include it Java will c. If you don't include it you must have a 0 parameter constructor coded in the super class or no constructors coded at all in the super class d. The sub class constructor containing the super call and the called super...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment:...
MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms. Detailed specifications: Define an...
a gymnastic school with hundreds of students. It needs a database to track all the different...
a gymnastic school with hundreds of students. It needs a database to track all the different classes that are being offered, who is assigned to teach each class, and which students attend each class. Also, it is important to track the progress of each student as they advance. Design a database for the following requirements: Students are given a student number when they join the school. This is stored along with their name, date of birth, and the date they...
we will be taking data in as a file. you cannot use the data values in...
we will be taking data in as a file. you cannot use the data values in your source file but you must read in everything into variables and use it from there. First we need to include <fstream> at the top of our file. We will need to create an input file stream to work and ifstream. ifstream is a datatype. Create a variable with the datatype being ifstream. Variable is drfine by using the member accessor operator to call...
Classes/ Objects(programming language java ) in software (ATOM) Write a Dice class with three data fields...
Classes/ Objects(programming language java ) in software (ATOM) Write a Dice class with three data fields and appropriate types and permissions diceType numSides sideUp The class should have A 0 argument (default) constructor default values are diceType: d6, numSides: 6, sideUp: randomValue 1 argument constructor for the number of sides default values are diceType: d{numSides}, sideUp: randomValue 2 argument constructor for the number of sides and the diceType appropriate accessors and mutators *theoretical question: can you change the number of...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT