Writing, compiling and running your programs from Eclipse.
In this assignment we will practice compiling and running our programs on Eclipse like we did in class. Here is a tutorial that will walk you to the steps of creating, compiling and running a program:
Practice creating, compiling and running small program before you tackle the program given for this assignment.
Program 1 (50 points):
Write an “are you a fan” quiz program. The program will quiz the user on a topic of your choosing (keep the topic appropriate). For quiz ideas, check out this website (http://www.allthetests.com/fan–quizzes–tests–Fantests.php) Note: Please cite all sources you use in your code, in the form of a comment.
Your quiz must contain 10 questions. These 10 questions include at least two of each of the following different types of questions:
Numeric Response: The user enters in a numeric response to an open-ended question. I recommend prompting the user to enter an integer. If you choose to use floats, be specific to the user about how they should enter their response (i.e. rounded and/or a certain number of decimal places).
How many states are there in the United States? Please enter an integer.
Multiple choice. The user enters in a character ‘a’ through ‘e’ for their answer.
What is the rough estimate of the population of New York City? Please enter a character a – e.
- 1 million
- 3 million
- 5 million
- 8 million
- 10 million
True/False (Boolean): The user enters True or False in response to a statement.
Alaska was the last state to enter the Union, true or false? Please enter True or False.
After the user enters an answer, the program should tell the user if the answer was correct or not. If the user’s answer was incorrect, then show the right answer. For each correct answer, the user earns 1 point.
At the end of the quiz, tell the user their final score, plus a fun statement about how much of a “fan” they are of the quiz’s topic (use an if else if else structure, which means you need at least 3 different fun statements based on the user’s score).
Here is a sample run:
Program 2 (50 points):
For this part of the assignment, you will create two files: one that contains the definition of a Robot class and one that contains the main method and tests the Robot class. Here are the specifications:
Create a class Robot with two attributes, an integer recording its total distance traveled and a double with its current battery level. Your class should implement the following methods:
- A constructor that takes no arguments. It should set the distance to 0 and the battery level to 3.
- A method charge, which takes an integer and increases the battery level by this amount.
- A method currentSpeed, which takes no arguments and returns the robot’s current speed. This is calculated by squaring its battery level and multiplying by 2. (Note that the easiest way to square a number on a computer is to multiply it by itself.)
- A method moveForward, which takes an integer distance giving the distance the robot, should move. This method increases the robot’s total distance traveled and also multiplies the battery level by
(1 − )
𝑑𝑖𝑠𝑡𝑎𝑛𝑐𝑒 + 1
- A method estTimeHome, which takes no arguments and returns the time the robot would take to retrace its steps at its current speed. Thus, the return value is the total distance it has traveled divided by the current speed (calculated as described above).
Test your Robot class by taking it through the following steps:
- Create a Robot.
- Get its current speed; the value should be 18.
- Have it move forward 9
- Get its current speed; the value should now be slightly less than 18 (returned as 0.179999999…).
- Have it calculate its estimated time home; the value should be very slightly over 50.
- Charge it by 5
- Get its current speed; the value should now be 18.
Display the numeric results with two decimal places.
Note 1: Please make sure to submit well-written programs for these programming tasks. Good identifier names, useful comments, indentation, and spacing will be some of the criteria that will be used when grading this assignment.
Note 2: This assignment can be and must be solved using only the materials that have been discussed in class. Do not look for alternative methods that have not been covered as part of this course.