Lab 7 - Arrays CSE 110 Principles of Programming with Java Spring 2021 Due March 26th 2021, 11:59PM Arizona Time 1 Lab Objectives The following objectives will be met at the end of this lab - •...

1 answer below »
Java Lab 7 - Arrays (due on Mar 27th @ 23:30PM) & Assignment 4 (due on Mar 28th @ 23:30PM). Please treat the Lab and the assignment on separate solution submission as per the attached instructions.



Lab 7 - Arrays CSE 110 Principles of Programming with Java Spring 2021 Due March 26th 2021, 11:59PM Arizona Time 1 Lab Objectives The following objectives will be met at the end of this lab - • Declare and create arrays • Traverse an array • Search an array for a particular element • Apply functions to make your program modular 1.1 Arrays For this lab we will be working with arrays. Remember that an array is a collection of variables of the same datatype and is referenced by a common name. The size of the array must be known prior to creating an array in JAVA. The index of an array ranges from 0 to (size - 1). For this lab we will accept an array from the user (user will define the size and the elements of the array). We will then define a couple of functions to simulate two specific operations on the user defined array. The first function will display the elements of the array when called. The second function will search the array and display only the negative numbers in the array. 1.2 Lab Objectives The source code file Lab7.java that you will create in this section, is what you will upload as your submission file to Canvas by the due date for this lab. Please ensure that the source code runs on your machine and produces the correct output as required. Overall Objective: For this lab, you will write a JAVA program that accepts the size of an integer array from the user. Create an integer array of the user input size and then accept the elements of the array from the user. You will then define two functions to do the following - the first function will display the elements of the array when called. The second function will search the array and display only the negative numbers in the array. For this section, you will create a new project in your IDE called Lab7 and create a source file called Lab7.java inside that project. The following requirements must be met to successfully complete this section - Obj.1 [(1+4) points] Define a static void function called displayArray(int arr[]) that displays the elements of the array i.e. you are to print all the values stored inside the array. You can choose how to format the output. Obj.2 [(1+4) points] Define a static void function called displayNegativeElements(int arr[]) that will search for and display only the negative numbers in the array. You can choose how to format the output. Obj.3 [1 point] Within the main() function create and object of the Scanner class for user input. Obj.4 [1 point] Within the main() function you must accept the size of the array from the user. Obj.5 [1 point] Within the main() function you must create an integer array of the size given by the user in objective 4. Obj.6 [3 points] Within the main() function you must use a loop to accept the elements of the array. Obj.7 [4 point] Within the main() function you must call both functions you defined to display the array and the negative numbers in the array. Note: You can use extra functions as you see fit. There is no limitation on how many functions you use to achieve the end result. Once you are done editing your source code, make sure to save it (save often to prevent loss of data and work) and then compile your source code. The next step is to follow the submission guidelines in Section 2 of this document and turn your lab in. 1.3 Comment Header Please include the following comment lines at the top of your Lab7.java file. Make sure you fill in the required fields as well. Listing 1: Comment Header 1 // ================================================ 2 // Lab7 . java 3 // Name : 4 // ASU ID : 5 // Time taken to complete t h i s lab : 6 // ================================================ 1 2 Submission Guidelines Please follow the guidelines listed below prior to submitting your source code file Lab7.java on Canvas - 1. Make sure that your source code file is named as Lab7.java prior to submitting. 2. Make sure that you have completed all the objectives listed in section 1.2. 3. Include the completed comment header shown in section 1.3 at the top of your source code file 4. Submit your Lab7.java file only to the Canvas link for Lab 7 by March 26th 2021, 11:59PM Arizona Time. 3 Grading Rubric As noted in Section 1.2, each of the five objectives have their own points. They are independent of each other and you will be scored for each objective that you complete successfully. Partial points will be awarded for partially completing objectives. 2 Lab Objectives Arrays Lab Objectives Comment Header Submission Guidelines Grading Rubric Assignment 4 - Five Methods CSE 110 Principles of Programming with Java Spring 2021 Due March 28th 2021, 11:59PM Arizona Time 1 Assignment Objectives & Requirements 1.1 Assignment Objectives After completing this assignment the student should be able to: • Write methods that have no parameters or return value • Write methods that have parameters • Write methods that have return values 1.2 Assignment Requirements For this assignment you are given the following file - Assignment4.java (you must complete this file). 2 Problem Description and Given Information Within the Assignment4.java file, you must define the following static methods. In the main() method, you may write any code that wish to test the methods you have been asked to define. 1. Write (define) a static method named displayGreeting(), that takes no arguments and returns no value. When this function is called, it should print the text ”Hello, and welcome!”. Example: displayGreeting() will print Hello, and welcome! 2. Write (define) a static method named displayText(), that takes a single integer argument and returns no value. When this function is called, it should print the value of the argument that was passed to it. Examples: displayText(123) will print 123 displayText(4156) will print 4156 displayText(2+3) will print 5 3. Write (define) a static method named printTotal(), that takes three int arguments. When this function is called, it should print the sum of the three arguments passed to it. This function should return no value. Examples: printTotal(0, 0, 0) will print 0 printTotal(0, 1, 3) will print 4 printTotal(100, 23, 2) will print 125 4. Write (define) a static method named getTotal(), that takes three int arguments. When this function is called, it should return the sum of the three arguments passed to it as an int. Examples: getTotal(0, 0, 0) will return 0 getTotal(0, 1, 3) will return 4 getTotal(100, 23, 2) will return 125 5. Write (define) a static method named getAverage(), that takes three int arguments. When this function is called, it should return the average of the three arguments passed to it as a double. Examples: getAverage(0, 0, 0) will return 0.0 getAverage(0, 1, 3) will return 1.33333 getAverage(100, 13, 7) will return 40.0 1 3 Method Template Here is a template that you may use or refer to when defining your methods. All of your five methods will follow this template; you must provide the components designated by the angle brackets ¡ ¿. static < returntype="">< methodname=""> (< parameters="">) { < methodbody=""> } 4 To Do After reading the problem description, you may follow the given steps to starting your assignment - 1. Create a new project in your IDE called Assignment4 2. Create a new source file called Assignment4.java inside the project 3. Copy the contents of the source file provided for this assignment into the one created by you 4. Follow the comment sections along with the requirements listed in section 2 to complete your code 5. Compile and run your program to check for errors 6. Make sure you submit your source code file Assignment4.java to the submission link by the deadline 5 Submission Guidelines Please follow the guidelines listed below prior to submitting your source code file Assignment4.java on Canvas - 1. Make sure that your source code file is named Assigment4.java prior to submitting. 2. Make sure that your input and output matches the format shown in section 2 3. Make sure that you have completed the comment section at the top of the source code file 4. Submit your Assignment4.java file only to the Canvas link for Assignment 4 by March 28th 2021, 11:59PM Arizona Time. 6 Grading Rubric Criteria Points All required files are submitted 10 Each file includes the comment head section completed. Code is neat and well organized 10 Good naming conventions for all identifiers Good use of whitespace Descriptive comments Partial credit can be awarded Code compiles with no syntax errors 20 No Partial credit can be awarded No credit will be awarded for structure or logic if your code does not compile Code passes structure tests 30 Code outputs results Code passes logic tests 30 Partial credit is awarded based on number of tests passed No credit will be awarded for logic if your code does not pass all structure tests TOTAL 100 2 Assignment Objectives & Requirements Assignment Objectives Assignment Requirements Problem Description and Given Information Method Template To Do Submission Guidelines Grading Rubric
Answered Same DayMar 26, 2021

Answer To: Lab 7 - Arrays CSE 110 Principles of Programming with Java Spring 2021 Due March 26th 2021, 11:59PM...

Vibhav answered on Mar 27 2021
150 Votes
javaLab/Assignment4.java
javaLab/Assignment4.java
public class Assignment4 {
    public static vo
id displayGreeting() {
        System.out.print("Hello, and welcome!");
    }
    public static void displayText(int x) {
        System.out.print(x);
    }
    public static void printTotal(int x, int y, int z) {
        System.out.print(x+y+z);
    }
    public static int getTotal(int x, int y, int z) {
        return x+y+z;
    }
    public static double getAverage(int x, int y, int z) {
        return (x+y+z)/2.0;
    }
    public static void main(String[] args) {
        displayGreeting();
        System.out.println();
        displayText(4);
        System.out.print...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here