Question
Idk how to do go about this. It's Java**** public class Item { private String name; private double price; public static final double TOLERANCE =
Idk how to do go about this. It's Java****
public class Item
{
private String name;
private double price;
public static final double TOLERANCE = 0.0000001;
public Item(String name,double price)
{
this.name = name;
this.price = price;
}
public Item()
{
this("",0.0);
}
public Item(Item other)
{
this.name = other.name;
this.price = other.price;
}
public String getName()
{
return name;
}
public double getPrice()
{
return price;
}
public void setName(String name)
{
this.name = name;
}
public void setPrice(double price)
{
this.price = price;
}
public void input()
{
// Code to be written by student
}
public void show()
{
// Code to be written by student
}
public String toString()
{
return "Item: " + name + " Price: " + price;
}
public boolean equals(Object other)
{
if(other == null)
return false;
else if(getClass() != other.getClass())
return false;
else
{
Item otherItem = (Item)other;
return(name.equals(otherItem.name)
&& equivalent(price, otherItem.price));
}
}
private static boolean equivalent(double a, double b)
{
return ( Math.abs(a - b) <= TOLERANCE );
}
}
Be sure to include your test runs at every step in your submission. Using the Item class provided to you for download, write a method called input that prompts the user for the items name and price and accepts the appropriate input from the console. Write a method called show that outputs the item information to console. Test your methods by creating a class called TestItem that contains a main method. Your main method should create a default Item object, gets input from the user using the input method of the class, and then outputs the item to the console using the show method.
Add a static method to the TestItem class that averages an array of type double and returns the answer as a double. Create an array of type Item that collects the input for 3 items in a loop and calculates the average price. Output the items and average price to the user from the console in the appropriate format (money).
Change your Java program so that it tests to see if one of the items is named Peas (not case sensitive) Your program should only output the average that is calculated if one of the items is named Peas, otherwise output no average output.
Change your Java program so that it will accept a practically unlimited number of items. To accomplish this you may use an array larger than would be practical. Use 100 for array size if you choose this option. Optionally you may store your items in an ArrayList instead of an array. In either case, for the input let any negative input be your sentinel value for price. Do not include this negative value in determining your average. You will continue to use the feature from step 3, testing if one of the items is named Peas, otherwise output no average output.
Add a static method to your Java program in the TestItem class that outputs Welcome to Tri-C in a pop-up message box before the items and prices are output. You should use the showMessageDialog method of Javas JOptionPane class for this task.
Add a static method to your TestItem class that takes an array of items and outputs them in reverse order of input. Output your items in both forward and reverse and print the average if one of the items is named Peas in your test runs.
Change your Java program so that after it produces its output, it asks users if they would like to process another group of items. The program should terminate when the user enters no (not case sensitive). Otherwise it should continue processing names and prices.
Change your Java program so that it will check for duplicate items input and produce an error message that allows the user to re-enter that item
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