Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Inventory Project:

843789Nov 11 2009 — edited Nov 12 2009
I truly am new to java in school and have a final project I am currently working on with much difficulty. I have no desire to do this after school however it was a requirement, so here I am. i have a project that was divided into 6 parts, I was able to get through the first 3 with relative ease but the last 3 I am completely lost, I can compile the first 3 parts which is included separately, then I add the last 3 parts and have no luck compiling it, can I get some direction? it says i have 3 errors but I dont know how to fix it. The part im up to is Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform the corresponding actions on the item name, the number of units in stock, and the price of each unit. An item added to the inventory should have an item number one more than the previous last item.

the first part that runs smoothly is as follows:

import java.util.Scanner;

class Inventory {

String number;
String name;
int quantity;
double price;
double restockfee;

public Inventory(String Num, String N, int Q, double P, double F)
{
name = N;
number = Num;
quantity = Q;
price = P;
restockfee = F;
}


public void setName(String N)
{
name = N;
}
public String getName()
{
return name;
}

public void setNumber(String Num)
{
number = Num;
}
public String getNumber()
{
return number;
}

public void setQuantity(int Q)
{
quantity = Q;
}
public int getQuantity()
{
return quantity;
}

public void setPrice(double P)
{
price = P;
}
public double getPrice()
{
return price;
}

public void setRestockfee(double F)
{
restockfee = F;
}
public double getRestockfee()
{
return restockfee;
}

public double getInventoryValue()
{
return price * quantity;
}

public static double getTotalValueOfAllInventory(Inventory [] inv)
{
double tot = 0.00;

for(int i = 0; i < inv.length; i++)
{
tot += inv.getInventoryValue();
}
return tot;
}

public String toString()
{
return "Car Name: "+name + "\nCar Stock Number: "+number+"\nSticker Price: $"+price+"\nMiles per gallon:"+"\nQuantity Available: "+quantity + "\nIn-Stock Value: $"+getInventoryValue();
}

}


class Product extends Inventory {

String style;
double restockfee;


public Product(String style, double restockfee, String Num, String N, int Q,
double P, double F) {
super(Num, N, Q, P, F);
this.style = style;
this.restockfee = restockfee;
}

public double getInventoryValue()
{
return super.getInventoryValue() + (super.getInventoryValue() * restockfee);
}

public String toString()
{
StringBuffer sb = new StringBuffer("\nCar Style: ").append(style).append("\n");
sb.append(super.toString());

return sb.toString();
}

}



public class Cars2

{
public static void main(String args[])
{

double restockfee = 0.05;

Product[] inventory = new Product[7];

inventory[0] = new Product("Nissan" , restockfee, "1","Maxima",5, 29000, .4);
inventory[1] = new Product("Honda" , restockfee, "2","Accord", 12, 26535, .9);
inventory[2] = new Product("Hyundai", restockfee, "3","Sonata", 10, 21475, .3);
inventory[3] = new Product("BMW", restockfee,"4","750", 2,48499, .2);
inventory[4] = new Product("Volkswagen", restockfee, "5", "Passat", 2, 27999, .0);
inventory[5] = new Product("Infiniti", restockfee, "6", "M35", 4, 41969, .1);
inventory[6] = new Product("Lexus", restockfee, "7", "IS300", 6, 34000, .99);

Product temp[] = new Product[1];

System.out.print( " Thank you for using Ric's Car Smart Inventory " );
System.out.println();
System.out.println();



for(int j = 0; j < inventory.length - 1; j++)
{
for(int k = 0; k < inventory.length - 1; k++)
{
if(inventory[k].getName().compareToIgnoreCase(inventory[k+1].getName()) > 0)
{
temp[0] = inventory[k];
inventory[k] = inventory[k+1];
inventory[k+1] = temp[0];
}
}
}


for(int j = 0; j < inventory.length; j++)
{
System.out.println(inventory[j].toString());
}


System.out.printf("\n\nTotal value of inventory is: $%.2f\n\n" , Inventory.getTotalValueOfAllInventory(inventory));
return;

}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 10 2009
Added on Nov 11 2009
9 comments
469 views