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

  Write java application that lets you create strong password

Write a java application that lets you create a strong password. The password should follow the following some criteria: (use your own creativity to come up with specific requirements).

  How do i display a message in the browsers status bar

How do I display a message in the browser's status bar? What are the main differences between applets and applications?

  Determine whether a given credit card number is valid or not

Implement Luhn's algorithm in a program to determine whether a given credit card number is valid or not. You must test if the number of digits in the input is in the valid range (13 to 16), run Luhn's algorithm to test its validity.

  Write a bash script larger x y that compares the sizes

Write a bash script larger X Y that compares the sizes of two specified files X and Y, and reports which file is larger. For example, if X is larger, the output should be "File X is larger", while if Y is larger, the output should be "File Y is la..

  Write a program that reports the comparison for all models

Write a program that reports the comparison for all models represented in the data file in a table, reporting: the number of each model installed; the total uptime, the total number of failures, and the overall MTBF.

  Create a function that multiplies numeric matrices

Create a function that multiplies numeric matrices on an element-by-element basis.

  Write java program to read in sequence of hourly temperature

Write down Java program which reads in sequence of hourly temperature readings over 24-hour period using arrays. Your program must find and show maximum and minimum temperatures.

  What is an infinite loop

What is an "off-by-one error"? Give an example for it from your experience.What is an infinite loop? Write a for statement to demonstrate it.

  Huge integer class

Huge Integer Class) Create a class HugeInteger which uses a 40-element array of digits to store integers as large as 40 digits each. Provide methods parse, toString, add and subtract. Method parse should receive a String, extract each digit using met..

  Write a on the popularity of java

Write a 4-5-page research-oriented paper in APA format that focuses on the "Popularity of Java". The paper must cite at least 5 references, not including the textbook or the Bible.

  Write a class named retailitem

Write a class named RetailItem that holds data about an item in a retail store. The class should have the given member variables:

  Integrate ibm watson tool into your software

Integrate IBM Watson tool into your software. Extract both Personality Insights and Tone analyzer form the data set. Initial thoughts on how to represent/model the output for the next stage.

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