Site Search

## Student Learning Objectives

• Demonstrate the ability to use a while inside a Java program
• Demonstrate the ability to use a sentinel value to signal the end of a loop
• Include a file header comment to identify the author, account, and honor code
• Browse through the Java Programming Style Guide for other standards and conventions to use in CS 110.

## Program 6 Assignment

Program 6 is based on Chapter 5, Programming Challenge Exercise 8 of your textbook.

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.

1. Normal case: two or more double values entered by the user
2. One number: the user enters only one double number as input
• Make that value entered both the largest, the smallest, and the mean values
3. 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

```Enter a number or 0 to quit: `50.5`
Enter a number or 0 to quit: `22.2`
Enter a number or 0 to quit: `30.3`
Enter a number or 0 to quit: `100.0`
Enter a number or 0 to quit: `0`
Largest: 100.0
Smallest: 22.2
Mean: 50.75
```

Sample Session: One number entered

```Enter a number or 0 to quit: `5.5`
Enter a number or 0 to quit: `0`
Largest: 5.5
Smallest: 5.5
Mean: 5.5

```

Sample Session: No numbers entered

```Enter a number or 0 to quit: `0`
You did not enter any numbers
```

## What to turn in at the start of the next lab

• Be sure your project is saved in your `U:\programs\program6\` folder in your CS 110 account.
• `BigAndSmall.java` should be saved in program6 folder
• The file should begin with a file header comment
• Note: if you complete the assignment on your personal computer, you must copy the file(s) to your your CS network account
• An easy way to copy the files is to use a USB portable drive, email, or a digital drop box
• Instructions for accessing your U-Drive remotely is provided if you are unable to physically come into the Hebeler lab to copy the files
• Your program will be checked online. You do not need to print out a copy of your program to turn in.
• The assignment is due at the start of Lab 12.
• If you are unable to finish in time, you may turn in what you have done to receive partial credit for the assignment.
• You are allowed to drop one program assignment score for the quarter

Include a file header comment at the top of every source code file. Include the assignment number, your cs110 account number, your name, completion time, and the honor code.

Remember, program assignments are to be done on your own. If you receive help understanding or debugging the assignment, you must acknowledge the person who helped. You must do the coding on your own.

```//**********************************************************
// Assignment: Program 6
// Account: (Enter your cs110 account number here)
//
// Author: (Enter your full name here)
//
// Completion time: (Enter the total number of hours you
//                   spent on the assignment)
//
// Honor Code: I pledge that this program represents my own
//   program code. I received help from (enter the names of
//   others that helped with the assignment, write no one if
//   you received no help) in understanding and debugging my program.
//*********************************************************
```

20 points possible
CS 110 Program 6 Grading Sheet (PDF)

• 10 points - Output Correctness
• The program loops until the sentinel value (`0`) is entered (2)
• The program displays the correct largest value (2)
• The program displays the correct smallest value (2)
• The program displays the correct mean value (2)
• Duplicate the sample output exactly, do not make up your own words or formatting (2)
• 4 points - Boundary Conditions
• The algorithm works correctly when only one number entered by the user (2)
• The algorithm works correctly when no numbers entered by the user (2)
• 2 points - Comments and Alignment
• File header comment are present and complete
• Skip a blank line before every single-line comment
• Generally one single-line comment is needed for every four to six lines of code
• Use jGRASP Generate CSD to properly align your printout
• Alignment and indentation are important. Read through the Java Style Guide for CS 110 expectations
• 2 points - Identifier Names
• Meaningful identifier names used for all identifiers
• Variable names should begin with a lower case letter, and each subsequent word should start with an upper-case letter.
• Avoid the use of abbreviations in choosing variable names
• Read through the Java Style Guide for CS 110 expectations.
• 2 points - Creation of Assignment Folder, File, and Printouts
• Folder `U:\programs\program6\` created correctly on your network U:\ drive
• Java source code file saved as `BigAndSmall.java`