Cse 110- write partial code using a loop to produces given


ASSIGNMENT

Topics

• Loops

Note: Your programming assignments require individual work and effort to be of any benefit. Every student must work independently on his or her assignments. This means that every student must ensure that neither a soft copy nor a hard copy of their work gets into the hands of another student. Sharing your assignments with others in any way is NOT permitted.

Violations of the University Academic Integrity policy will not be ignored. The university academic integrity policy is found at https://www.asu.edu/studentaffairs/studentlife/judicial/academic_integrity.htm

Use the following Guidelines:

? Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc).

? Keep identifiers to a reasonably short length.

? User upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects).

? Use tabs or spaces to indent code within blocks (code surrounded by braces). This includes classes, methods, and code associated with ifs, switches and loops. Be consistent with the number of spaces or tabs that you use to indent.

? Use white space to make your program more readable.

? 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.

? 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, and that it is updated accordingly from assignment to assignment. (If not, -1 Pt) style (1pt)

? //*********************************************************** // Name: your name
? // Title: title of the source file
? // Author: (if not you, put the name of author here)

? // Description: Write the description in your words.
? // Time spent: how long it took you to complete the assignment // Date: the date you programmed //**********************************************************

Part 1: Writing Exercise:

The following are the exercises about the loops in Java. Write the answers in a comment block before the code of Part2.

1. What output the program produces?

public class SimpleLoop

{
public static void main(String[] args)

{
int i = 0;

int limit = 6;
while (i < limit)

{
System.out.println("i = " + i);

i++; }

} }

2.

3.

i=6 i=8 i = 10 i = 12 i = 14 i = 16 i = 18 ...

i = 98

What is the output?

for (int i = 1; i < 3; i++)

{
for (int j = 1; j < 5; j++)

{

} }

Write partial code using a loop to produces the following output:

System.out.println(i + "

" + j);

Note: The answers to the questions (1 through 3) above should be typed in the block of comments in the java file such as;

Part 2: Programming

Write a Java program called Assignment4.java. There are two tasks in this assignment. Your program will ask for user choice and based on which it will switch between the two tasks.

After performing the selected task, your program should ask the user if the user wants to do another execution of the program. If the user opts to continue, then your program should loop again and display the option for two tasks, else it should terminate.

Read the instructions carefully for each task. Follow the instruction one by one. Don't go to the next step if your program does not return the proper output from previous step.

Task 1: Choice A

Ask user to enter a sequence of integer inputs until user enters -1. Then compute the following based on user input

? The smallest and largest of the inputs - print them to screen

? The number of even and odd inputs - print them to screen Cumulative totals. For example if the input is 1 7 2 9, the program should print 1 8 10 19

Task 2: Choice B

Display a pattern of asterisks ‘*'. Read an integer and display, using asterisks, a filled diamond of the given side length. For example if the side length is 4, the program should display.

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

If the user input is invalid (not a positive integer), the program displays a message and asks the user to reenter a positive integer (see sample output).

Sample output: The user inputs are in RED

Choice Action ---------------------------

A B Q ?

AEnter a sequence of integers, -1 to quit: 1 7 2 9 -1

Largest: 9
Smallest: 1
Number of even: 1
Number of odd: 3 Cumulative sum is: 1 8 10 19

What action would you like to perform?

AEnter a sequence of integers, -1 to quit: 12 9 10 1 7 8 -1

Largest: 12
Smallest: 1
Number of even: 3
Number of odd: 3
Cumulative sum is: 12 21 31 32 39 47

What action would you like to perform?

BEnter side length:

2*

*** *

What action would you like to perform?

bEnter side length:
-12
Not valid input- enter a positive value:

Enter side length: 5*

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

Compute Display asterisks Quit

Display Help

What action would you like to perform?

*

q

Use only the Java statements that have been covered in class to date. DO NOT use any other items out of the Chapter 1- 4 (for example no Array, Array List, exit() etc.). If in doubt, ask. If you use them, then you lose the points of task. Complete each step one by one. Don't copy any code developed by others. Don't give your code to others. Don't use any algorithm, which you cannot understand. Your assignment file is checked by the MOSS (by Stanford Univ.), which is a program to detect cheatings.

Submit your homework by following the instructions below:

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

? Go to the course web site (my.asu.edu), and then click on the on-line Submission tab. Login to the page by typing your email and password

? Submit your Assignment4.java file on-line. Make sure to choose Hw4 from drop-down box.

? Assignment4.java should have the following, in order:

o In comments, the assignment Header described in "Important Note"
o Answer to questions in Part 1
o The working Java code for Part 2
o The Assignment4.java file must compile and run as you submit it. You confirm this by viewing your submission results.

? Important Note: You may resubmit as many times as you like until the deadline, but we will only mark your last submission.

? NO LATE ASSIGNMENTS WILL BE ACCEPTED.

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Cse 110- write partial code using a loop to produces given
Reference No:- TGS02192429

Expected delivery within 24 Hours