Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Data structure programming question! I need help please and if you can send me your code screenshot!!! Part 1 : Item class Start by choosing

Data structure programming question!
I need help please and if you can send me your code screenshot!!!
Part 1: Item class
Start by choosing one sort of items that is of interest to you. For example: vacation or travel information, real estate property, or restaurant. It is prohibited to use any of the following as your item: person, car, student, book, bank account, movies, pet, animal, song, or videogame.
Your Item class must have the following characteristics:
has a meaningful name. Do not name your class Thing or Item.
has exactly two private instance variables, a string and an integer. The instance variables must have meaningful names to describe the characteristics of your item.
implement a constructor for your Item class that takes two input parameters to initialize the two instance variables. The order of the input parameters must be as String then int.
implement getters and setters for all the instance variables of your Item.
implement toString method that returns a string representation of your item where the instance variables are in one line and separated by tab. Do not add any text to the output of this method other than the values of the two instance variables.
implement the equals method for your Item where two items are considered equal when they have the same values in both of the instance variables. Note that, the equality of string attributes should be case insensitive. For example, "MATH", "math" and "Math" should be equal. Note: to compare strings in Java use the String's equalsIgnoreCase method. For example, the following code prints true:
String str1= "Hello";
String str2= "hello";
System.out.println(str1.equalsIgnoreCase(str2));
Part 2: Upload data from a text file to an array of Item objects
Create a .txt file that includes data about a collection of items. Each line in the file represents one item where the string and integer separated by tab (e.g., abc 10). Add at least 20 lines to your text file. Make sure to repeat some of the string values in the file.
Create another class in your project, called ArrayDriver. Use the name of your item instead of .
In the main method, declare an array, called Arr, that can hold up to 20 items.
In the main method, ask the user to enter file name then read the user input. Create a File object using the input file name. Create a Scanner object to read from the file.
Write a loop to read the text file. You need to read one field from the file at a time. Basically, for each line in the text file, you will read the two fields in each row using the following Scanner methods: next then nextInt.
Use the values read from one line from the file to instantiate an Item object then add that object to Arr.
After uploading the data to the array, write a 'for' loop to print on the screen all objects in Arr to make sure that the data to read correctly.
Part 3: Methods to process Item array
Implement the following five methods in ArrayDriver.
Test the methods from the main method using itemArr as input.
Remember: string comparison is case insensitive.
overallAvg: a method that takes an array of Item objects as input and returns the average of the integer attributes of all items in the array.
count: a method that takes two inputs, an array of Item objects and an Item object. The method returns the number of items in the input array that are equal to the input item. Remember, two items are equals if they have the same value for both instance variables.
groupAvg: a method that takes two input parameters, an array of Item objects and a string. The method returns the average of the integer attributes of items with string attribute equal to the input string. For example, groupaverage(itemArr,"abc") returns the average of the integer attributes for all objects with string attribute equal to "abc".
lessThan: a method that takes two input parameters, an array of Item objects and an integer. The method returns an array of Item objects that contains all objects with integer attribute less than the input integer. For example, lessThan(itemArr,50) returns an array of items with integer attribute <50.
groupEdit: a method that takes three input parameters, an array of Item objects, a string, and an integer. For each item in the input array with string attribute equals to the input string, the method edits the items integer attribute by adding the input integer. For example, groupEdit(itemArr,"abc",10) adds 10 to the integer values of each item in itemArr with string value "abc".
OTHER REQUIREMENTS
Comment your code classes with Javadocs style comments (see Appendix H).
Use good coding style throughout including:
correct private/public access modifiers.
consistent indenting.
meaningful variable names.
normal capitalization conventions.
other aspects of easy-to-read code.
GRADING
You must use the exact same name (case matched) for all fields and methods as specified in the above description. The method input

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions