New to java looking for a little help adding a feature
Hello,
I am trying to take an Inventory2 and products file and add the ability to sort the list by the title of the movie. Is there a way to add a feature to my existing code or will I have to redesign it using a compare class?
Here is the code:
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
// begin Class Inventory2
publicclass Inventory2
{
publicstaticvoid main( String[] args)
{
// create inventory of items
Products title1 =new Products(1,"Movie 1", 2, 39.99);
Products title2 =new Products(2,"Movie 2", 6, 29.99);
Products title3 =new Products(3,"Movie 3", 7, 29.99);
Products title4 =new Products(4,"Movie 4", 8, 59.99);
//Display the inventories one at a time.
title1.showProducts();
title2.showProducts();
title3.showProducts();
title4.showProducts();
}// End main method
}// End Inventory2
// Begin class products
publicclass Products
{
privateint productNum;
private String name =new String();
privateint units;
privatedouble price;
publicint getproductNum()// Get productNum
{
return productNum;
}
publicvoid setproductNum(int productNum)// productNum
{
this.productNum = productNum;
}
public String getName()// Get productNane
{
return name;
}
publicvoid setName(String name)// Set productNane
{
this.name = name;
}
publicint getUnits()// Get units
{
return units;
}
publicvoid setUnits(int units)// Set units
{
this.units = units;
}
publicdouble getPrice()// Get price
{
return price;
}
publicvoid setPrice(double price)// Set price
{
this.price = price;
}
// Constructors
Products()
{// Empty Constructor
}//End constructor
// Constructor that takes arguments
Products(int _productNum, String _name,int _units,double _price)
{
// Constructor
productNum = _productNum;
name = _name;
units = _units;
price = _price;
}// End constructor
// Computes value of Products
publicdouble valueOfProducts()
{
return price * units;
}
// Displays the details of the Products
publicvoid showProducts()
{
System.out.println();// prompt
// Output messages
System.out.println("Name: "+name);
System.out.println("Number "+productNum);
System.out.println("Items Available = "+units);
System.out.println("Price $"+price);
System.out.println("Value of Inventory"+name+" is = $"+valueOfProducts());
}// End display
}// End class

