Inventory part 2 help displaying result
:confused:I'm trying to figure out why the results are not showing on the bottom. Can anyone tell me what I'm doing wrong? Any Suggestions with my code?
I'm working on the Inventory Program part 2
I'm supposed to create an array and display the information on each book.
Thanks
Code:
import java.text.NumberFormat;
import java.util.Arrays;
public class Inventory { //Class Inventory
public static void main(String[]args){ //Main method
NumberFormat nf = NumberFormat.getCurrencyInstance();
Product bookInfo = new Product(); //Creates object for Product class
bookInfo.getTitle(); //Calls getTitle method
bookInfo.getISBN(); //Calls getISBN method
bookInfo.getUnits(); //Calls getUnits method
bookInfo.getPrice(); //Calls getPrice method
bookInfo.getValue(); //Calls getValue method
bookInfo.getTotalValue(); //Calls getTotalValue method
System.out.println("\t\tWelcome to the Book Store Inventory!"); //Displays welcome message
System.out.println(); //Creates space for readability
System.out.println("Title\t\t\tISBN\t\tUnit Quantity\tPrice\t\tValue"); //Creates header for table
System.out.println(); //Creates space for readability
final int ARRAY_LENGTH = 4;
Product book[] = new Product[ARRAY_LENGTH];
book [0] = new Product("Programming 101",123456789,15,14.99);
book [1] = new Product("Java for beginners",987345524,2,15.95);
book [2] = new Product("Learning to Program",134553256,12,6.99);
book [3] = new Product("How to Java",146542334,4,12.49);
for(int i = 0; i<book.length; i++){
System.out.println(book[0]); //Displays 1st element of each array.
System.out.println(); //Creates space for readability
System.out.println(book[1]); //Displays 2nd element of each array.
System.out.println(); //Creates space for readability
System.out.println(book[2]); //Displays 3rd element of each array
System.out.println(); //Creates space for readability
System.out.println(book[3]); //Displays 4th element of each array
System.out.println(); //Creates space for readability
System.out.println(); //Creates space for readability
} //End for loop
} //Ends method
} //Ends class
Code:
import java.util.Scanner;
public class Product { //Creates class Product
private String title; // Declares bookName as string variable
private int ISBN, units; // Declares ISBN and unitQ as integer variables
private double price, value; // Declares Price and Value as double variables
private static double totalValue; // Declares totalValue as double static variable.
Scanner userIn = new Scanner(System.in); //Names Scanner userIn
public Product(){ }//Creates and terminates BookInventory Empty Constructor
public Product(String titleIn, int ISBNIn, int unitsIn, double priceIn){//Creates BookInventory Constructor with parameters
this.setTitle (titleIn);
this.setISBN (ISBNIn);
this.setUnits (unitsIn);
this.setPrice (priceIn);
}//Terminates BookInventory Constructor with parameters
public void setTitle(String titleIn){
this.title = titleIn; //Set instance variable title
}
public String getTitle(){
return title; //Get title value
}
public void setISBN(int ISBNIn){
this.ISBN = ISBNIn; //Set instance variable ISBN
}
public int getISBN(){
return ISBN; //Get ISBN value
}
public void setUnits(int unitsIn){
this.units = unitsIn; //Set instance variable units
}
public int getUnits(){
return units; //Get units value
}
public void setPrice(double PriceIn){
this.price = PriceIn; //Set instance variable price
}
public double getPrice(){
return price; //Get price value
}
public void setValue(){
value= price * (int)units; //Set and calculates value of price * units
}
public double getValue(){
return value; //Get value price * units
}
public double getTotalValue(){
return totalValue; //Gets totalValue value
}
public void displayInventory(){
}
}