COMP 110-001 - Introduction to Programming (Spring 2009)

Lab 4

25 points

Assigned: February 13th

Due: February 19th by midnight

Description

This lab will give you practice writing loops.

Part 1

On the course webpage, you will find BasketballScores.java. Copy and paste the program into a new Java file in jGRASP, and edit the Program Header to reflect your name and assignment information. You must add to the program the capability to read in a list of UNC basketball scores (non-negative integers!) one at a time from the user and output the following statistics:

The end of the input is indicated by the user entering a negative sentinel value. Note that the sentinel value is NOT used in computing any of the statistics. Output messages have been provided for you in the program as given.

Suggestions for starting the assignment:

Part 2

On the course webpage, you will find Triangle.java. Copy and paste the program into a new Java file in jGRASP, and edit the Program Header to reflect your name and assignment information. The program as given asks the user to enter the size of a triangle as an integer from 1-10. You must add to the program where indicated by the comment //YOUR CODE HERE the ability to display a triangle of the size indicated by the user. The directions for displaying the triangle follow.

From your text, Savitch & Carrano, "Java: An Introduction to Problem Solving and Programming", 5th edition.

"Display the triangle by writing lines of asterisks. The first line will have one asterisk, the next two, and so on, with each line having one more asterisk than the previous up to the number entered by the user. On the next line write one fewer asterisk and continue by decreasing the number of asterisks by 1 for each successive line until only asterisk is displayed. For example, if the user enters 3, the output would be"

*
**
***
**
*

HINT: Use nested for loops, where the outer loop controls the number of asterisks to draw on the current line and the inner loop draws the asterisks.

Submission

For this assignment you will need to create a Jar file that contains the source code for BasketballScores.java AND Triangle.java that you edited as part of this assignment. Follow these instructions for creating a Jar file.
The Jar file you submit must be named yourlastname_lab4.jar, where yourlastname is your last name

Submit yourlastname_lab4.jar via the UNC Blackboard System under "Assignments → Lab 4" before the deadline.

Grading