The recomendations I saw online as well as my own common sense tell me I just need to change the printing choice. I don't think I am doing this right at all, can anyone tell me if I am even on the right track, and if not what may help.
Here are my original classes from Part 3...
Cars Class
// Week 6 Inventory Program Part 3
// Inventory program that stores data in class
// Uses Array to return data
// With added SUV subclass & added MPG
public class Cars
{
private static int itemNumber[] = new int[8];
private static String name[] = new String[8];
private static int units[] = new int[8];
private static double price[] = new double[8];
private static int i = 0;
public Cars(){ }//
public Cars(int _itemNumber, String _name, int _units, double _price)//
{
itemNumber[i] = _itemNumber;
name[i] = _name;
units[i] = _units;
price[i] = _price;
i = i + 1;
}
public static double valueOfInventory(double p,int u)
{
return p*u;
}
public static void showInventory()
{
for(int j=0;j<i;j++){
System.out.println("\nItem Number: 1090" + itemNumber[j]);
System.out.println("Car Name: " + name[j]);
System.out.println("MPG: " + Suv.mpg[j]);
System.out.println("Number In Stock: " + units[j]);
System.out.println("Unit Price : " + price[j]);
System.out.println("Value of inventory: " + valueOfInventory(price[j], units[j]));
System.out.println("Value with restocking fee: " + Suv.valueOfInventory(price[j], units[j]));
}
}
public static void showValueofInventory()
{
double totalVal = 0.00;
for (int j = 0; j < i; j++)
{
totalVal = totalVal + valueOfInventory(price[j], units[j]);
}
System.out.println("\n**Total Value of In Stock Cars is = " + totalVal);
}
}
Products Class
//Week 6 Product Array Class
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
public class Products
{
public static void main( String[] args)
{
Cars p = new Suv(1, "Ford Ranger", "20", 5, 14000);
Cars q = new Suv(2, "Ford Focus", "24", 2, 13000);
Cars r = new Suv(3, "Ford F150", "18", 12, 18000);
Cars s = new Suv(4, "Ford Probe", "22", 1, 7500);
Cars t = new Suv(5, "Ford Escort", "28", 4, 4500);
Cars u = new Suv(6, "Ford Aspire", "30", 1, 10000);
Cars v = new Suv(7, "Ford Taurus", "21", 8, 9750);
Cars w = new Suv(8, "Ford Explorer SUV", "16", 6, 24000);
///show inventory
Cars.showInventory();
///show total value of inventory
Cars.showValueofInventory();
}
}
Suv Class
//Week 6 Added Subclass with MPG & Restocking Fee
public class Suv extends Cars
{
static String mpg[] = new String[8];//New product feature itemCode added
private static int i = 0;
//Constructor
public Suv(int _itemNumber, String _name, String _mpg, int _units, double _price)
{
super( _itemNumber, _name, _units, _price);
mpg[i] = _mpg;
i++;
}
public static double valueOfInventory(double p,int u)
{
return 1.05*Cars.valueOfInventory(p, u);
}
}
I made changes to my Cars class, since thats where I designated how the results should print. Here is my modified class...
// Week 7 Inventory Program Part 4
// Inventory program that stores data in class
// Uses GUI to return data
// With added SUV subclass & added MPG
import java.awt.FlowLayout; // specifies how components are arranged
import javax.swing.JFrame; // provides basic window features
import javax.swing.JLabel; // displays text and images
import javax.swing.SwingConstants; // common constants used with Swing
public class Cars extends JFrame
{
private static int itemNumber[] = new int[8];
private static String name[] = new String[8];
private static int units[] = new int[8];
private static double price[] = new double[8];
private static int i = 0;
public Cars(){ }//
public Cars(int _itemNumber, String _name, int _units, double
_price)//
{
itemNumber[i] = _itemNumber;
name[i] = _name;
units[i] = _units;
price[i] = _price;
i = i + 1;
}
public static double valueOfInventory(double p,int u)
{
return p*u;
}
public static void showInventory()
// LabelFrame constructor adds JLabels to JFrame
{
super( "Testing JLabel" );
setLayout( new FlowLayout() ); // set frame layout
for(int j=0;j<i;j++){
// JLabel constructor with a string argument
label1 = new JLabel( "Item Number: 1090" + itemNumber[j] + "Car Name:
" + name[j] + MPG: " + Suv.mpg[j] + "Number In Stock: " + units[j] +
"Unit Price : " + price[j] + "Value of inventory: " + valueOfInventory
(price[j], units[j] + "Value with restocking fee: " +
Suv.valueOfInventory(price[j], units[j]" );
label1.setToolTipText( "This is label1" );
{
}
}
public static void showValueofInventory()
{
double totalVal = 0.00;
for (int j = 0; j < i; j++)
{
totalVal = totalVal + valueOfInventory(price[j], units[j]);
}
System.out.println("\n**Total Value of In Stock Cars is = " +
totalVal);
add( label1 ); // add label1 to JFrame
}
}
These are all the errors I received
c:\gui>javac cars.java
cars.java:54: ')' expected
label1 = new JLabel( "Item Number: 1090" + itemNumber[j] + "Car Name: " + nam
e[j] + MPG: " + Suv.mpg[j] + "Number In Stock: " + units[j] + "Unit Price : " +
price[j] + "Value of inventory: " + valueOfInventory(price[j], units[j] + "Value
with restocking fee: " + Suv.valueOfInventory(price[j], units[j]" );
^
cars.java:54: not a statement
label1 = new JLabel( "Item Number: 1090" + itemNumber[j] + "Car Name: " + nam
e[j] + MPG: " + Suv.mpg[j] + "Number In Stock: " + units[j] + "Unit Price : " +
price[j] + "Value of inventory: " + valueOfInventory(price[j], units[j] + "Value
with restocking fee: " + Suv.valueOfInventory(price[j], units[j]" );
^
cars.java:54: ';' expected
label1 = new JLabel( "Item Number: 1090" + itemNumber[j] + "Car Name: " + nam
e[j] + MPG: " + Suv.mpg[j] + "Number In Stock: " + units[j] + "Unit Price : " +
price[j] + "Value of inventory: " + valueOfInventory(price[j], units[j] + "Value
with restocking fee: " + Suv.valueOfInventory(price[j], units[j]" );
^
cars.java:54: ';' expected
label1 = new JLabel( "Item Number: 1090" + itemNumber[j] + "Car Name: " + nam
e[j] + MPG: " + Suv.mpg[j] + "Number In Stock: " + units[j] + "Unit Price : " +
price[j] + "Value of inventory: " + valueOfInventory(price[j], units[j] + "Value
with restocking fee: " + Suv.valueOfInventory(price[j], units[j]" );
^
cars.java:54: not a statement
label1 = new JLabel( "Item Number: 1090" + itemNumber[j] + "Car Name: " + nam
e[j] + MPG: " + Suv.mpg[j] + "Number In Stock: " + units[j] + "Unit Price : " +
price[j] + "Value of inventory: " + valueOfInventory(price[j], units[j] + "Value
with restocking fee: " + Suv.valueOfInventory(price[j], units[j]" );
^
cars.java:54: ';' expected
label1 = new JLabel( "Item Number: 1090" + itemNumber[j] + "Car Name: " + nam
e[j] + MPG: " + Suv.mpg[j] + "Number In Stock: " + units[j] + "Unit Price : " +
price[j] + "Value of inventory: " + valueOfInventory(price[j], units[j] + "Value
with restocking fee: " + Suv.valueOfInventory(price[j], units[j]" );
^
cars.java:54: ';' expected
label1 = new JLabel( "Item Number: 1090" + itemNumber[j] + "Car Name: " + nam
e[j] + MPG: " + Suv.mpg[j] + "Number In Stock: " + units[j] + "Unit Price : " +
price[j] + "Value of inventory: " + valueOfInventory(price[j], units[j] + "Value
with restocking fee: " + Suv.valueOfInventory(price[j], units[j]" );
^
cars.java:54: ';' expected
label1 = new JLabel( "Item Number: 1090" + itemNumber[j] + "Car Name: " + nam
e[j] + MPG: " + Suv.mpg[j] + "Number In Stock: " + units[j] + "Unit Price : " +
price[j] + "Value of inventory: " + valueOfInventory(price[j], units[j] + "Value
with restocking fee: " + Suv.valueOfInventory(price[j], units[j]" );
^
cars.java:54: not a statement
label1 = new JLabel( "Item Number: 1090" + itemNumber[j] + "Car Name: " + nam
e[j] + MPG: " + Suv.mpg[j] + "Number In Stock: " + units[j] + "Unit Price : " +
price[j] + "Value of inventory: " + valueOfInventory(price[j], units[j] + "Value
with restocking fee: " + Suv.valueOfInventory(price[j], units[j]" );
^
cars.java:54: ';' expected
label1 = new JLabel( "Item Number: 1090" + itemNumber[j] + "Car Name: " + nam
e[j] + MPG: " + Suv.mpg[j] + "Number In Stock: " + units[j] + "Unit Price : " +
price[j] + "Value of inventory: " + valueOfInventory(price[j], units[j] + "Value
with restocking fee: " + Suv.valueOfInventory(price[j], units[j]" );
^
cars.java:54: ';' expected
label1 = new JLabel( "Item Number: 1090" + itemNumber[j] + "Car Name: " + nam
e[j] + MPG: " + Suv.mpg[j] + "Number In Stock: " + units[j] + "Unit Price : " +
price[j] + "Value of inventory: " + valueOfInventory(price[j], units[j] + "Value
with restocking fee: " + Suv.valueOfInventory(price[j], units[j]" );
^
cars.java:54: ';' expected
label1 = new JLabel( "Item Number: 1090" + itemNumber[j] + "Car Name: " + nam
e[j] + MPG: " + Suv.mpg[j] + "Number In Stock: " + units[j] + "Unit Price : " +
price[j] + "Value of inventory: " + valueOfInventory(price[j], units[j] + "Value
with restocking fee: " + Suv.valueOfInventory(price[j], units[j]" );
^
cars.java:76: illegal start of expression
public static void showValueofInventory()
^
cars.java:76: illegal start of expression
public static void showValueofInventory()
^
cars.java:76: ';' expected
public static void showValueofInventory()
^
cars.java:76: ';' expected
public static void showValueofInventory()
^
16 errors

New Topic/Question
Reply




MultiQuote








|