Starting from:
$29.99

$23.99

CIS 212 Assignment

The goals of this assignment are to get your development environment set up and to provide experience with using loops and conditionals in Java and with building a simple executable Java application.

 

Write a Java program that calculates the sum of a list of positive integers entered by the user. To accomplish this, you’ll repeatedly prompt the user to enter an integer and use special-case integer values to determine when to print the sum, clear the sum, and quit the application. You may get user input either from the console or by writing a simple UI. We’ll go over the former method in class. Your program should:

 

1.  [10] Display text asking the user to enter an integer. You should indicate to the user that entering -1 will print the current sum, -2 will reset the sum to 0, and -3 will quit the application. For example:

 

Enter a positive integer (-1 to print, -2 to reset, -3 to quit):

 

2.  [20] Read an integer from the user.

 

3.  [10] If the user entered -1, print the current sum and then prompt the user for another integer.

 

4.  [10] If the user entered -2, set the current sum back to 0 and then prompt the user for another integer.

 

5.  [10] If the user entered -3, print the sum and then quit the application.

 

6.  [10] If the user entered a positive integer, add it to the current sum and then prompt the user for another integer.

 

7.  [10] If the user entered a negative number less than -3, simply ignore the number and then prompt the user for another integer.

 

8.  [20] Write code that is clear and efficient. Specifically, your code should be indented with respect to code blocks, avoid code that is commented out or otherwise unused, use descriptive and consistent class/method/variable names, etc.

 

Here’s output from a sample run:

 

Enter a positive integer (-1 to print, -2 to reset, -3 to quit):

 

-1

 

Sum: 0

 

Enter a positive integer (-1 to print, -2 to reset, -3 to quit):

1

 

Enter a positive integer (-1 to print, -2 to reset, -3 to quit):

 

2

 

Enter a positive integer (-1 to print, -2 to reset, -3 to quit):

 

3

 

Enter a positive integer (-1 to print, -2 to reset, -3 to quit):

 

-1

 

Sum: 6

 

Enter a positive integer (-1 to print, -2 to reset, -3 to quit):

 

-4

 

Enter a positive integer (-1 to print, -2 to reset, -3 to quit):

 

-1

 

Sum: 6

 

Enter a positive integer (-1 to print, -2 to reset, -3 to quit):

 

-2

 

Enter a positive integer (-1 to print, -2 to reset, -3 to quit):

 

-1

 

Sum: 0

 

Enter a positive integer (-1 to print, -2 to reset, -3 to quit):

 

-3

 

Sum: 0

 

Zip the Assignment1 folder in your Eclipse workspace directory, name the .zip file <Your Full NameAssignment1.zip (e.g., EricWillsAssignment1.zip), and upload the .zip file to Canvas (see Assignments section for submission link).

More products