CSE 110 – Assignment 4   Solved

35.00 $

Category: Tags: , , , ,
Click Category Button to View Your Next Assignment | Homework

You'll get a download link with a: zip solution files instantly, after Payment

Securely Powered by: Secure Checkout

Description

5/5 - (5 votes)

                         Topics: Chapter 3 & 4

  • Control Flow  — Conditional and repetition (loop) statements

 

Your programming assignments require individual work and effort to be of any benefit. Every student must work independently on his or her assignments. You must work alone on the assignments – no collaboration of any kind is permitted. You cannot use Google, StackOverflow, Chegg or any other on-line resources to look up for the solution. Sharing your assignments with others in any way is NOT permitted. Violations of the University Academic Integrity policy will not be ignored.

 

Violations of the University Academic Integrity policy will not be ignored.     The university academic integrity policy is found at https://provost.asu.edu/academic-integrity

Important Note: All submitted assignments must begin with the descriptive comment block.  To avoid losing trivial points, make sure this comment header is included in every assignment you submit.

/*————————————————————————-

// AUTHOR: your name

// FILENAME: title of the source file

// SPECIFICATION: description of the program

// YOUR Lab Letter and Name of the TA for your Closed lab

// FOR: CSE 110- homework #- days and time of your class

// TIME SPENT: how long it took you to complete the assignment

//———————————————————————-*/

Reasonably good amount of comments should be added in your program so that it is easy for other people to understand it. Please see the comment style in the textbook.

Part 1: Written Exercises: NonePart 2: Programming: (20 points)

Write a program called Assignment4 (saved in a file Assignment4.java) that reads in a sequence of positive integers until a user enters -1 to quit (we don’t know how many numbers the user may enter)

The loop continues to ask for user input until the user enters negative one:  

Enter a positive integer. Enter -1 to quit.

 

For each positive integer, check if it is a prime number or not.

If it is prime then print out:

 

The number X is a prime number.

 

If it is not prime print out:

 

The number X is not a prime number.

 

Note that X is a positive number entered by the user

 

Once the user enters -1, then the program stops asking for more positive integers, and computes the maximum and minimum among integers entered by the user, and the sum, the count, and the average of these integers. These computations DO NOT include -1 — the last read number.

 

(note that max, min, sum, and count will be computed through iterations of a loop, see the example

Average.java in your book)

 

Your average should be formatted with two digits to the right of the decimal point.

Hint:

There are two parts to this program.

Part 1: reads a sequence of positive numbers and finds the maximum, minimum, sum, count, and average.

Part 2:  for each positive integer, we need to determine if it is a prime number or not.

A prime number (integer) is an integer that can be divided only by itself and 1. For example, 7 is a prime number and 6 is not (6 can be divided by 2 and 3). We can check if an integer can be divided by another integer using the remainder operator (%). If the remainder is 0, it can be divided. And we need to check this for all integers between 2 and n-1 for a positive integer n. Hint: Write a separate program to find if a number is prime or not, and then include it to the first part mentioned above.

Sample Output: (the integers entered by a user are shown in bold)

Enter a positive integer. Enter -1 to quit.

43

The number 43 is a prime number.

Enter a positive integer. Enter -1 to quit.

6

The number 6 is not a prime number.

Enter a positive integer. Enter -1 to quit.

7

The number 7 is a prime number.

Enter a positive integer. Enter -1 to quit.

9

The number 9 is not a prime number.

Enter a positive integer. Enter -1 to quit.

12

The number 12 is not a prime number.

Enter a positive integer. Enter -1 to quit.

4

The number 4 is not a prime number.

Enter a positive integer. Enter -1 to quit.

-1

 

The maximum positive number is: 43

The minimum positive number is: 4

The sum is: 81

The count of number(s) is: 6

The average is: 13.5

Submit your homework by following the instructions below:

*********************************************************************************

  • Upload your java file to GradeScope. The link is provided on Canvas
  • java should have the following in order:
  • In comments, the assignment Header described in “Important Note”.
  • The working Java code requested in Part #2.
  • The Assignment4.java file must compile and run as you submit it. You can confirm this by viewing your submission results.
  • Please check your code after you submit your assignment and make sure you are passing the two test cases.

 

  • Assignment4.zip