Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help with writing part 2 of this Java program? Put your name as a comment on the top of the class. Import the scanner
Please help with writing part 2 of this Java program?
- Put your name as a comment on the top of the class.
- Import the scanner package.
- Write the name of the class, perhaps YOURNAME_Lab1.
- Write the main method header (public static void main(String[] args)).
- Inside main, create the scanner object using System.in as the parameter.
- Ask the user to provide their name and age using the appropriate prompts, and scanner commands.
- Then print the users name and age.
- Save the file if you havent already done so. Then compile the file and run it.
Part 2 Array Operations
For this part of the lab, you'll be writing methods to work with 1D arrays. We will expect you to know how to create an array, and store and retrieve information from them.
- Add a new java class to your existing folder.
- Put your name as a comment on the top of the class.
- You will be generating random numbers so import java.util.Random.
- You should consider developing the methods for this project incrementally.
- In main, use an initializer list create an array of integers called nums holding the following values: 1, 4, 13, 43, -25, 17, 22, -37, 29.
- Write a method, called findLargest, that returns the largest value in the array and have the main print the result.
- Create an integer array of size 20, called data and write a method to fill the array with random integers from [-100, 100].
- Recall that Randoms nextInt(x) method returns a value from 0 to x-1. The upper bound is exclusive, in other words. Modify the values to fit the required ranges.
- Use the findLargest method you previously wrote to return the largest value in data for the main to print.
- Print the sum of the largest values from nums and data.
Print the contents of data.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started