Question

Lab #7 CSE110 - Arizona State University Topics • Basic arrays Coding Guidelines • Give identifiers...

Lab #7

CSE110 - Arizona State University

Topics

• Basic arrays

Coding Guidelines

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

• Keep identifiers to a reasonably short length.

• Use 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.

• Use comments after the ending brace of classes, methods, and blocks to identify to which block it

belongs.

Assignment/Lab Documentation

At the beginning of each programming assignment you must have a comment block with the following

information:

/*-------------------------------------------------------------------------

// AUTHOR: your name

// FILENAME: title of the source file

// SPECIFICATION: description of the program

// FOR: CSE 110- Lab #7

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

//-----------------------------------------------------------*/

Getting Started

Create a class called Lab7. Use the same setup for setting up your class and main method as you did for the

previous assignments. Be sure to name your file Lab7.java.

Hints

• (Page 250) An array will be used in this program.

• The lecture and code example videos are also good references for this lab.

1

Task Overview

The overall goal of this lab is to allow the user to enter five integers into an array. The program will then

print out each of these integers + 1.

Part 1: Initial Setup

The following needs to be done for the initial setup:

• Create a Scanner object - be sure to import the Scanner class

• Declare a constant int called SIZE - set it equal to 5

• Create an array of ints called array of size SIZE

Note: See the table on page 252 if you need help creating your array.

Part 2: Filling the Array

Using a loop, iterate through the array and use the Scanner class to read ints into all five positions in the

array. A prompt for input is optional. See the lecture videos for examples of this being done. If this part is

completed successfully, your array should contain five elements after the user enters five integers.

Part 3: Displaying the Output

To separate the outputs, include a println statement stating something along the lines of:

Processing each array element...

Now, write another loop which prints out 1 + each of the array?s elements on a separate line. For example,

if one of the elements is 4, your program should print a 5. See below for a full example.

Note

• It isn’t necessary to prompt a user to input integers in the beginning. It isn’t a problem if you do,

though.

• It is possible to achieve the output of this lab without using arrays and with only one loop. However,

that would defeat its purpose. Please use an array and please write out the two loops to complete this

lab for full credit.

• Labs are not graded by a program, so you do not need to spend a large amount of time making the

output match perfectly with the sample below. Do, however, make sure your output is reasonable.

The goal here is for you to demonstrate that you understand the underlying concepts.

Sample Output

Below is an example of what your output should roughly look like when this lab is completed. All text in

bold represents user input.

Sample Run 1:

0

1

2

3

4

2

Processing each array element...

1

2

3

4

5

Sample Run 2:

-5

6

0

1

1

Processing each array element...

-4

7

1

2

2

Submission

Submit your Lab7.java to the Submission Server. Go to the Submission Server site located on the course

website, login, then click on Lab Submissions in the left frame. Choose Lab7 from the dropdown box, click

on the browse button and find where you saved your Lab7.java on your computer. Upload the file to the

site and then click on the Submit button.

Your file will be submitted and a screen will show up displaying if your program compiled and what your

output is when run on some sample input.

You should then check to make sure that the actual file submitted properly and is readable to the grader.

To do so click on Grades in the frame on the left of the page and then click on the 0 underneath Lab7. You

will again see that your program compiled and the sample output, but you should scroll down to the bottom

of the screen and make sure your file is readable as well.

Important Note: You may resubmit as many times as you like until the deadline, but we will only

mark your last submission.

3

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class second {
   public static void main(String[] args)
   {
   int array[] = new int[5];
       Scanner s = new Scanner(System.in);
   for(int i=0;i<5;i++)
   {
       array[i]=s.nextInt();
   }
   for(int j=0;j<5;j++)
   {
       System.out.println(array[j]+1);
   }
  
   }

}

012341123455 4 -6011-7122

Add a comment
Know the answer?
Add Answer to:
Lab #7 CSE110 - Arizona State University Topics • Basic arrays Coding Guidelines • Give identifiers...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring...

    Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring a variable, you usually want to initialize it. Remember you cannot initialize a number with a string. Remember variable names are case sensitive. Use tabs or spaces to indent code within blocks (code surrounded by braces). Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Problem...

  • Parallel Arrays Summary In this lab, you use what you have learned about parallel arrays to...

    Parallel Arrays Summary In this lab, you use what you have learned about parallel arrays to complete a partially completed Java program. The program should either print the name and price for a coffee add-in from the Jumpin’ Jive coffee shop or it should print the message: "Sorry, we do not carry that.". Read the problem description carefully before you begin. The data file provided for this lab includes the necessary variable declarations and input statements. You need to write...

  • Arizona State University - CSE205 Assignment #9 Due Date Friday, March April 3rd, 5:30pm Important: This...

    Arizona State University - CSE205 Assignment #9 Due Date Friday, March April 3rd, 5:30pm Important: This is an individual assignment. Please do not collaborate. No late assignment will be accepted. Make sure that you write every line of your code. Using code written by someone else will be considered a violation of the academic integrity and will result in a report to the Dean's office. It must be submitted on-line (Course website). Go to "GradeScope" tab on Canvas -> CSE205...

  • I wrote some code and it builds but everytime I run it, It shows the error...

    I wrote some code and it builds but everytime I run it, It shows the error message in the else statement ASU CSE 100 Lab #7 Due date/Time: Friday, Oct. 13th, 2017 at 5:30pm What this Lab Is A Learn to create and use istream object to read data from a text file Learn to create and use ofstream object to write program output into a text file Learn to use a while loop to read a text file line...

  • Lab 19 - History of Computer Science, A File IO Lab FIRST PART OF CODING LAB:...

    Lab 19 - History of Computer Science, A File IO Lab FIRST PART OF CODING LAB: Step 0 - Getting Starting In this program, we have two classes, FileIO.java and FileReader.java. FileIO.java will be our “driver” program or the main program that will bring the file reading and analysis together. FileReader.java will create the methods we use in FileIO.java to simply read in our file. Main in FileIO For this lab, main() is provided for you in FileIO.java and contains...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • Count Occurrences in Seven Integers Using Java Single Dimension Arrays In this assignment, you will design...

    Count Occurrences in Seven Integers Using Java Single Dimension Arrays In this assignment, you will design and code a Java console application that reads in seven integer values and prints out the number of occurrences of each value. The application uses the Java single dimension array construct to implement its functionality. Your program output should look like the sample output provided in the "Count Occurrences in Seven Integers Using Java Single Dimension Arrays Instructions" course file resource. Full instructions for...

  • **JAVA PLEASE!!** CSE205 Assignment 2 ASCII Terrain Generator 5Opts Topics: Arrays Multidimensional Arrays Metho...

    **JAVA PLEASE!!** CSE205 Assignment 2 ASCII Terrain Generator 5Opts Topics: Arrays Multidimensional Arrays Methods Loops and Conditionals Description The goal of this assignment is for you to produce a simple procedurally generated terrain map out of ASCII character symbols. This will be done through simple probability distributions and arrays Use the following Guideline s: 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....

  • Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete...

    Homework 3: Input Validation 1   Objectives control structures console-based user input using Scanner class writing complete programs using two classes: client and supplier 2   User Interface Specification This is a console-based I/O program. Display should go to System.out (print or println) and the program will get user input using the Scanner class. The flow of execution should be as follows: When the program starts, display a one-line introduction to the user Display a menu with 5 options 1. validate zip...

  • CM245 Lab 4 (Chapter 12) Submit online through D2L Implement solutions using the appropriate concepts from...

    CM245 Lab 4 (Chapter 12) Submit online through D2L Implement solutions using the appropriate concepts from Chapter 12. There is no need for any UML for this lab. Provide your implementation (java source code) and the output for each of the tests. There should be one class for exercises 12.2 and 12.3 and two classes for 12.4. I prefer one output file per programming exercise. For each problem you must handle the exception. 12.2 (InputMismatchException) Write a program that prompts...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT