Question: Part 1 : 1 . For this program you will be creating grocery item objects, putting them into an array of objects, and working with

Part 1:
1. For this program you will be creating grocery item objects, putting them into an array of objects, and working with them.
2. Create a new Java project called Lab7_2A.
3. Create a second class in the project named Item with the following:
a.4 instance variables
i. itemName (String)
ii. itemPrice (double)
iii. itemQuantity (double)
iv. itemTotalCost (double)
b. A constructor that receives inName (String), inPrice (double) and inQty (double) as parameters and fills in the instance variables with the parameter values
It should also call computeCost.
c. A void method named computeCost that calculates itemTotalCost by multiplying itemQuantity by itemPrice
d. A double method named getTotalCost that returns itemTotalCost
e. A String method named getItemName that returns itemName.
f. A String toString method that returns a String of all the instance variables with labels. (As we have done in previous lab assignments.)
g. Make all the instance variables private and the methods public. The methods will not have parameters unless the instructions list them.
4. Back in the main method
a. Create an array named cartArray of 4 Item objects.
b. For each element in cartArray
i. Read the item name, price, and quantity from the text file (Input7_2A.txt).(You will want to have local variables to hold these.)
ii. Instantiate the object sending those 3 pieces of data as parameters.
iii. Print the object using the toString shortcut.
iv. Get the total cost for that item (using the getTotalCost method) and add it to a local variable named subtotal
c. Calculate the tax for the whole order by multiplying subtotal by 0.0825
d. Calculate the total for the order by adding subtotal to tax.
e. Print a blank line and then print subtotal, tax, and total each on their own line with a label.
f. Use a new for-each loop to go through the array and find the item with the highest itemTotalCost.
g. After the loop print a blank line and then the highest itemTotalCost and its item name.
*Note Print all monetary amounts (price, tax, subtotal, etc. with 2 decimal places)
Reminder: You can do this by replacing itemPrice with String.format("$%.2f", itemPrice) when you print it or add it to toStrings return value.
Part 2:
1. Create a new Java project named Lab7_2B. In this program you will be reading in a file of daily temperatures for a month and determining the lowest, highest and average temp for that month.
2. Write a void method named fillList that receives an ArrayList of doubles as a parameter. It should do the following:
a. Read the month and year (integers) from the text file (Input7_2B.txt) and print those values with labels. (You must set up the text file inside this method, not in main.)
b. Read the daily temperatures and add them to the ArrayList.
3. Write a double method that receives an ArrayList of doubles and returns the highest value in the list.
4. Write a double method that receives an ArrayList of doubles and returns the lowest value in the list.
5. Write a double method that receives an ArrayList of doubles and returns the average temperature in the list.
6. Back in the main method:
a. Create an ArrayList of doubles.
b. Call fillList to fill in the ArrayList.
c. Call your other 3 methods and print their returned values.
Part 3:
1. In program Lab7_2C you will be working with an ArrayList of objects.
2. Create a second class named Visit and copy the Visit class from Lab6_2A into it.(Make sure you keep Lab7_2Cs package statement and dont copy Lab6_2As over.
a. Add a new String method named getType to Visit that will return the animals type.
b. Add a new String method named getName to Visit that will return the animals name.
3. Back in your main class:
a. Write a void method that receives an ArrayList of Visit objects and a String animal type (cat, dog, etc.) It should print all the objects with that type of animal.
b. Write a boolean method that receives an ArrayList of Visit objects and an animal name (String). It should return a true if the animal is found in the ArrayList and a false otherwise.
c. Write a method that will return a Visit object and receives an ArrayList of Visit objects. It should find and return the Visit object with the highest cost.
d. In the main method you should do the following:
i. Create an ArrayList of Visit objects.
ii. Read the values for each object from the text file (Input7_2C.txt) and for each set of data, create the object and add it to the ArrayList.
iii. Ask the user to input an animal type and then call the method from #a sending the ArrayList and animal type as parameters.
iv. Ask the user to input an animal name and then call the method from #b sending the ArrayList and animal type as parameters. Print a statement saying whether the name was found or not.
v. Call the method from #c sending the ArrayList as a parameter and print the returned object. (Also print a statement that this is the highest cost v

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!