Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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 http://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.

Java, Programming

  • Category:- Java
  • Reference No.:- M92205600

Have any Question?


Related Questions in Java

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assessment instructionsin this assessment you will design

Assessment Instructions In this assessment, you will design and code a simple Java application that defines a class, instantiate the class into a number of objects, and prints out the attributes of these objects in a spe ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Part a specification - robot simulationpart a

PART A Specification - Robot Simulation PART A Requirements To complete this assignment you will use the supplied eclipse project Robot P1/. It is already set up to execute a simple arm movement loop which you will build ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Can someone help me please with those question1what is the

Can someone help me please with those question 1:what is the best data type for student id datatime,currency,number,decimal 2:which relationshipis preferable? one to one,one to many,many to many 3:if you add table A's pr ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

Overviewyou are required to use java se 80 and javafx to

Overview You are required to use Java SE 8.0 and JavaFX to develop a Graphical User Interface (GUI) for the FlexiRent rental property management program created in Assignment 1. This assignment is designed to help you: 1 ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As