Write partial code using a loop to produces the given output

Assignment Help JAVA Programming
Reference no: EM131395785

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.

Reference no: EM131395785

Questions Cloud

Definitions by subclass or synonymous definitions : A triangle is "equilateral" if and only if a compass, when placed sequentially on two vertices and properly adjusted, strikes through the other two vertices.
Gaines and losses in total revenue : Illustrate the effect of the price change. Be sure to fully label the graph and illustrate the gaines and losses in total revenue associated with the change. What happens to total revenue? Did you make demand elastic or inelastic? Why?
Enumerative definitions or definitions by subclass : Determine whether the following are demonstrative definitions, enumerative definitions, definitions by subclass, synonymous definitions, etymological definitions, operational definitions, or definitions by genus and difference.- "Hammer" means a t..
Implement a little guessing game called bulls and cows : The guessing continues until the user gets four bulls, that is, has the four digits correct and in the correct order.
Write partial code using a loop to produces the given output : CSE 110- Write partial code using a loop to produces given output. 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.
Demonstrative definitions or enumerative definitions : Determine whether the following are demonstrative definitions, enumerative definitions, definitions by subclass, synonymous definitions, etymological definitions, operational definitions, or definitions by genus and difference.
Describe the concept of multifactorial etiology : Describe how the concept of multifactorial etiology relates to the natural history of disease and the different levels of prevention. How should the nurse incorporate these concepts into health promotion of clients in community settings? How shoul..
Calculate sea ready weighted average : Calculate Sea Ready's component cost of equity using the capital asset pricing model (CAPM):Assuming a 40% tax rate, calculate Sea Ready's weighted average cost of capital (WACC).
Choosing between the project : You are choosing between the following Project A and Project B.  If the interest rate is 8%, and the cash flow streams are as provided below, which would you select?  You can only select one.  Explain your selection.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd