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
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do...
Code in Java SAMPLE PROGRAM OUTPUT Because there are several different things your program might do depending upon what the user enters, please refer to the examples below to use to test your program. Run your final program one time for each scenario to make sure that you get the expected output. Be sure to format the output of your program so that it follows what is included in the examples. Remember, in all examples bold items are entered by...
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...
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”...
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...
3.2 Class Dictionary This class implements a dictionary using a hash table in which collisions are...
3.2 Class Dictionary This class implements a dictionary using a hash table in which collisions are resolved using separate chaining. The hash table will store objects of the class Data. You will decide on the size of the table, keeping in mind that the size of the table must be a prime number. A table of size between 5000-10000, should work well. You must design your hash function so that it produces few collisions. A bad hash function that induces...
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...
Objective The Final Project aims to demonstrate your ability to analyze data from a big database,...
Objective The Final Project aims to demonstrate your ability to analyze data from a big database, exercise use of arrays of objects, external classes, processing files and user interaction. For this project, you will design and implement a program that analyzes baby name popularities in data provided by the Social Security Administration. Every 10 years, the data gives the 1,000 most popular boy and girl names for kids born in the United States. The data can be boiled down to...
I am making a game like Rock Paper Scissors called fire water stick where the rules...
I am making a game like Rock Paper Scissors called fire water stick where the rules are Stick beats Water by floating on top of it Water beats Fire by putting it out Fire beats Stick by burning it The TODOS are as follows: TODO 1: Declare the instance variables of the class. Instance variables are private variables that keep the state of the game. The recommended instance variables are: 1. 2. 3. 4. 5. 6. A variable, “rand” that...