Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help with java program Part 1 Searching Continuing with arrays, we will now expect you to find information in an array and derive useful
Please help with java program
Part 1 Searching
Continuing with arrays, we will now expect you to find information in an array and derive useful properties from the information stored in an array.
- Start Eclipse.
- Change the workspace directory location to something "safe". You may want to temporarily choose the Desktop and then save the file to something permanent once you're done (e.g. a network drive or flash drive).
- Go to the File menu and select New Java Project. Call it YOURNAME_Lab1BArray.
- Create a main method, and create a 2D integer array called data, with a size of five (5) by five (5). Ask the user to input the values for this array (Scanners nextInt).
- Create a method called LongestPositiveSeries, that takes in a 2D array and finds the length of the longest continuous series of positive numbers in it.
- For example, if we had an array like this:
0 | 1 | 2 | 3 | 4 |
5 | -1 | -5 | -5 | 5 |
3 | -2 | 56 | 25 | -15 |
0 | 5 | 5 | 0 | 324 |
46 | 25 | 0 | 0 | 0 |
- The length would be 5. For this problem, 0 is considered non-negative and not positive, so we start counting from index [0, 1] (which is 1) to [1, 0] (which is 5) and end at index [1, 1] (which is 1).
- Hint: Consider using a basic linear search and modifying it to keep track of the current positive streak of numbers.
- Call that method in your main, for the array data.
- Print out the returned result from your method in your main, along with the content of data.
Part 2 Classes and Objects
For this part of the lab, you'll be writing methods to work with classes and objects.
- Create a new project, called YOURNAME_Lab1BClass.
- You should consider developing the methods for this project incrementally.
- Now create another class inside of your project. Go to the Project Explorer panel, right click on the project name and select New -> Class.
- Change the name of the class after it opens from Class1 to Person.
- Inside of your Person class add two class variables, one for first and one for last name.
- Create a default (no parameters) constructor method that sets their first name to "Bob and last name to Smith.
- Create an overloaded constructor method that takes in two parameters and sets their names to them. One parameter will be their first name and the second will be their last name.
- Create a getter/accessor method and setter/mutator method for both their first and last names.
- Lastly, create an overriden toString method that will return the persons first then last name.
- Hint: The method header would be:
@Override
public String toString()
- In your main method, create an object/instance of your Person class using the default constructor.
- Create another Person using the overloaded constructor. Have the values that are passed in as arguments come from user input (Scanners nextLine).
- Directly print out both peoples values using the toString method.
- Hint: The toString method is automatically called when an object/instance is placed into a WriteLine method call.
- Now change one persons first name to Aly and the other persons last name to Sanchez.
- Hint: Use the setters/mutators to do so. Please do not create two entirely new objects.
- Finally, print out both names for both people using the getters/accessors.
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