Question: I need java programing Part 1 : Item class Start by choosing one sort of Item that is of interest to you. ( For example:
I need java programing
Part : Item class
Start by choosing one sort of Item that is of interest to you. For example: vacation or travel information, real estate property, or restaurants. But dont feel limited to these ideas! Do not use any of the following as your Item: Person, Car, Student, Book, BankAccount, Movie, Pet, Animal, Song, or Videogame.
Name: Give your Item class a meaningful name. Do not name your class Thing or Item.
Instance Variables: Give your Item class exactly two private instance variables, a String and an Integer. Give them meaningful names that describe the characteristics of your Item.
Some methods:
public Item String s Integer n
Constructs an Item object that initializes the two instance variables. The order of the input parameters must be String then Integer.
Implement getters and setters for all the instance variables of your Item.
public String toString
Returns a String representation of your Item where the instance variables are on one line and tabseparated. Do not add any text to the output of this method other than the values of the two instance variables.
public boolean equalsItem o
compares your Item to the parameter o for equality. The equality of string attributes should be case insensitive. For example, "MATH", "math" and "Math" are equal. Note: to compare String objects in Java use the boolean equalsIgnoreCaseString s method from the String class. For example, the following code prints true:
String str "Hello";
String str "hello";
System.out.printlnstrequalsIgnoreCasestr;
Part : 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 eg abc Add at least 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 the number of items in your text file.
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 : 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.
public int overallAvg Item a
Returns the average arithmetic mean of the Integer attributes of all items in input array a
public int count Item a Item o
Returns the number of Items in the input array a that are equal to the input Item o Remember, two Items are equal if they have the same value for both instance variables, where String variables are equal if they differ only in case.
public int groupAvgItem a s
Returns the average of the Integer attributes of Items with String attribute equal to the input string. For example, groupAvgitemArr"abc" returns the average of the Integer attributes for all objects with String attribute equal to abc.
public Item lessThan Item a Integer i
Returns an array of Item objects that contains all objects with Integer attribute less than the input Integer. For example, lessThanitemArr returns an array of items with Integer attribute
public void groupEdit Item a String s Integer n
For each item in the input array with String attribute equal to the input string, the method edits the Items Integer attribute by adding n to the Integer value. Thus, groupEdititemArr"abc", adds to the Integer values of each item in itemArr with String value abc.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
