1.) Write a program, BigAndSmall.java, with a loop that lets the user enter a se
ID: 664977 • Letter: 1
Question
1.)
Write a program, BigAndSmall.java, with a loop that lets the user enter a series of double numbers. The user should enter 0 to signal the end of the numbers.
After the user has entered all the numbers, the program should display the largest number, the smallest number, and the mean (average) of the numbers entered.
Note: Program 6 needs only one Java class file, BigAndSmall.java, which contains a main method. You do not need to use a separate class file.
Boundary Conditions
There are three different conditions you need to consider with this program.
Normal case: two or more double values entered by the user
One number: the user enters only one double number as input
Make that value entered both the largest, the smallest, and the mean values
No values: the user immediately enters 0 as the signal to quit
Output the string "You did not enter any numbers"
Sample Sessions
Sample Session: Normal Case
Sample Session: One number entered
Sample Session: No numbers entered
2.)
Write a program that allows its user to play the dice game "Doubles"
Rules of the game
Player begins with ten dollars ($10.00)
The player places a bet amount and a pair of dice are rolled
If the two values showing on the pair of dice are the same (they rolled doubles), the player wins twice their bet amount
If the two values showing on the dice are not equal, then the player loses their bet amount
The game ends when the player is out of money
Class Design
The Die class will be similar to your Coin class done in Lab 11 except that the instance variable representing the die's face value should be an integer type (to store the value 1 to 6).
Constructor method: initialize the die's value to 0 and instantiate the Random number generator object
roll() method: use the Random object to simulate a die roll between 1 and 6 (see tip below)
equals(Die die2): returns true if both die have equal values, false otherwise
toString(): returns the string "one", "two", "three", etc. based on the integer value of the die
Tip: The Random class method nextInt(int n) returns a random integer value between 0 to n-1. To generate a random integer between 1 to 6 you can use
Sample Session
Explanation / Answer
import java.util.Scanner;
class BigAndSmall
{
public static void main(String[] args)
{
// Declare variables for user input
int number = 0;
// Generate a Scanner object to read from the keyboard
Scanner keyboard = new Scanner(System.in);
// Get the integers from users
while (number != -99)
{
System.out.print("Enter an integer number or -99 to quit:");
number = keyboard.nextInt();
}
System.out.println("You did not enter any numbers");
number = keyboard.nextInt();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.