Hello all,
I am fairly new to Java, and have had a terrible time with arrays thus far. I am attempting to complete a project using arrays to store inventory items (item number, name, unit price, and unit numbers) and need to output information using an array to hold the information. Another requirement for class is using a subclass to hold one more unique feature to the program and calculating an additional .05% increase on the total for output on all items.
I have so far built the array, class to set/get item information and also a calculation to calculate item value (based on units*price), I have also included a sub-method to include a category to my item.
I had used String.valueOf() to retrieve all information and have a parse.Double to convert all double money values from user input, but I can not seem to get the output section to retrieve information from the get methods in order to display the information to the user.
For each line of output I am receiving the errors:
THIS IS WHERE I BEGIN TO GET ALL OF MY ERROR MESSAGES: ADVISING THAT CANNOT FIND SYMBOL:
C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:90: error: cannot find symbol
inventoryTot += ProdArray.calcValue();
symbol: method calcValue()
location: class Product4
C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:91: error: cannot find symbol
restockTot += ProdArray.getFee();
symbol: method getFee()
location: class Product4
C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:99: error: bad operand type String for unary operator '+'
System.out.println("Item Number: ", +String.valueOf(ProdArray.getProductNumber()));
C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:100: error: bad operand type String for unary operator '+'
System.out.println("Product name: ", +String.valueOf(ProdArray.getProductName()));
C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:101: error: cannot find symbol
System.out.println("Product Category: ", +String.valueOf(ProdArray.getCatName()));
symbol: method getCatName()
location: class Product4
C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:102: error: bad operand type String for unary operator '+'
System.out.println("Units in stock: ", +String.valueOf(ProdArray.getProductUnits()));
C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:103: error: bad operand type String for unary operator '+'
System.out.println("Product price: ", +String.valueOf(ProdArray.getProductAmount()));
C:\Users\Chrystal\Desktop\JAVA\Inventory4\src\inventory4\Inventory4.java:105: error: cannot find symbol
System.out.println("Product re-stocking fee: " +String.valueOf(ProdArray.getFee()));
symbol: method getFee()
location: class Product4
8 errors
Is anyone able to help me with this problem?? Thank you all!!
// import java scanner
import Inventory4.Product4;
import java.util.Scanner;
// import Arrays to implement sort
import java.util.Arrays;
import java.io.*;
public class Inventory4 {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
// initialize scanner
Scanner input = new Scanner(System.in);
// welcome display output
System.out.print("Welcome to the Scrapbook Inventory Program!");
System.out.println(); // print blank line
System.out.print("This program will track supplies and accumulate the total ");
System.out.print("value of inventory."); // description of program
System.out.println(); // print blank line
//local variables assigned to collecting and displaying information in array
int maxCount = 5;
int i = 0;
double inventoryTot = 0.0;
double restockTot = 0.0;
// initialize Product4 array
Product4 ProdArray[] = new Product4[maxCount];
try{
String name;
String catName;
double number;
double units;
double amount;
// for loop to accumulate count (i) up to the maxCount amt of 5
// to obtain user input and store information in the array
for (i=0; i<ProdArray.length; i++)
{
// request user input for item name and store in array
System.out.println("Please enter the item name: " +String.valueOf(i+1)+ "of" +String.valueOf(maxCount));
name = input.nextLine();
//request user input for item number and convert double to a string
System.out.println("Please enter the item number: " +String.valueOf(i+1)+ "of" +String.valueOf(maxCount));
number = Double.parseDouble(input.nextLine());
// request user input for item units and convert double to a string
System.out.println("Please enter the number of units in stock: " +String.valueOf(i+1)+ "of" +String.valueOf(maxCount));
units = Double.parseDouble(input.nextLine());
// request user input for item price and convert double to a string
System.out.println("Please enter the price per unit: " +String.valueOf(i+1) + "of" +String.valueOf(maxCount));
amount = Double.parseDouble(input.nextLine());
// request user input for category of item- this is a call to the sub-method
System.out.println("Please enter the category of the item :" +String.valueOf(i+1) + "of" +String.valueOf(maxCount));
catName = input.nextLine();
ProdArray[i] = new Category4(name, number, units, amount, catName);
} // end for
} // end try
catch (Exception ec)
{
System.out.println(ec.getMessage());
System.exit(-1);
} // end catch
Arrays.sort(ProdArray);
//sortProduct(ProdArray);
for (i=0; i < maxCount; i++)
{
inventoryTot = ProdArray[i].calcValue();
restockTot = ProdArray[i].getFee();
}// end for
// output results
System.out.println("***Scrapbook Inventory Results***");
System.out.println(); // print blank line
for (i=0; i < maxCount; i++)
{
System.out.println("Item Number: ", +String.valueOf(ProdArray[i].getProductNumber()));
System.out.println("Product name: ", + String.valueOf(ProdArray[i].getProductName()));
System.out.println("Product Category: ", + String.valueOf(ProdArray[i].getCatName()));
System.out.println("Units in stock: ", + String.valueOf(ProdArray[i].getProductUnits()));
System.out.println("Product price: ", + String.valueOf(ProdArray[i].getProductAmount()));
System.out.println("Product total: " + String.valueOf(ProdArray[i].CalcValue()));
System.out.println("Product re-stocking fee: " +String.valueOf(ProdArray[i].getFee()));
System.out.println(); //print blank line
} //end for
// output total inventory results
System.out.println("Scrapbook inventory total: " +String.valueOf(inventoryTot));
System.out.println("Scrapbook inventory total with re-stocking fee: " +String.valueOf(restockTot));
} //end main
} //end Inventory
public class Product4 // beginning of super class
{
// declare all variables and array
public String ProdName;
public double ProdNum;
public double ProdUnits;
public double ProdAmt;
public Product4(){
}
//implicit call to 4 argument constructors
public Product4(String name, double number, double units, double amount)
{
ProdName = name;
ProdNum = number;
ProdUnits = units;
ProdAmt = amount;
}
// get and set methods for all objects
public void setProductName(String name)
{
setProductName(name);
}
public String getProductName()
{
return ProdName;
}
public void setProductNumber(double number)
{
setProductNumber(number);
}
public double getProductNumber()
{
return ProdNum;
}
public void setProductUnits(double units)
{
setProductNumber(units);
}
public double getProductUnits()
{
return ProdUnits;
}
public void setProductAmount (double amount)
{
setProductAmount(amount);
}
public double getProductAmount()
{
return ProdAmt;
}
public double CalcValue()
{
return getProductAmount()*getProductUnits();
}
} // end class
public class Category4 extends Product4{
private String catName;
public double restockFee;
public double fee = 0.05;
// constructors
public Category4(String name, double number, double units, double amount, String category)
{
super(name, number, units, amount);
catName= category;
}
// set and get methods of the subclass**** double check these- may need to
// use this.category=category; see example if need be
public void setCatName(String category)
{
setCatName(category);
}
public String getCatName()
{
return catName;
}
public double getFee()
{
return super.CalcValue()*fee;
}
} // end subclass