Inventory Program part 4

need help getting program to display labels

Page 1 of 1

1 Replies - 2633 Views - Last Post: 06 April 2008 - 08:37 PM Rate Topic: -----

#1 jlewis25   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 62
  • Joined: 22-March 08

Inventory Program part 4

Post icon  Posted 06 April 2008 - 08:11 PM

I'm stuck and don't know were to go this is what I need to happen
Modify the Inventory Program to use a GUI. The GUI should display the information one
product at a time, including the item number, the name of the product, the number of
units in stock, the price of each unit, and the value of the inventory of that product. In
addition, the GUI should display the value of the entire inventory, the additional attribute,
and the restocking fee.
and this is the code I have so far
public class Inventory3.3 {

	public static void main(String args []) {
		Inventory invent = new Inventory();
		Movie dvd;

		dvd = new Movie("Movie1", 1, "Cars", 5, 14.95);
		invent.add(dvd);
		dvd = new Movie("Movie2", 2, "The Departed", 10, 12.99);
		invent.add(dvd);
		dvd = new Movie("Movie3", 3, "American Gangster", 6, 19.99);
		invent.add(dvd);
		dvd = new Movie("Movie4", 4, "I am Legand", 3, 10.99);
		invent.add(dvd);

		invent.display();
	} //end main

} // end class Inventory3
class DVD {
	private int dvdItem;
	private String dvdRating;
	private String dvdTitle;
	private int dvdStock;
	private double dvdPrice;

	public DVD(int item,String dvdrating, String title, int stock, double price) {
		dvdItem  = item;
		dvdRating = rating;
		dvdTitle = title;
		dvdStock = stock;
		dvdPrice = price;
	} //end five-argument constructor

	// set DVD Item
	public void setDvdItem(int item) {
		dvdItem = item;
	} //end method  set Dvd Item

	//return DVD Item
	public int getDvdItem() {
		return dvdItem;
	} //end method get Dvd Item
	
	//set DVD Rating
	public void setDvdRating(String rating){
		dvdRating = rating;
	} //end method set Dvd Rating
	
	//return DVD Rating
	public String getDvdRating() {
		return dvdRating;
	}//end method get Dvd Rating 

	//set DVD Title
	public void setDvdTitle(String title) {
		dvdTitle = title;
	} //end method set Dvd Title

	//return Dvd Title
	public String getDvdTitle() {
		return dvdTitle;
	} //end method get Dvd Title

	public void setDvdStock(int stock) {
		dvdStock = stock;
	} //end method set Dvd Stock

	//return dvd Stock
	public int getDvdStock() {
		return dvdStock;
	} //end method get Dvd Stock

	public void setDvdPrice(double price) {
		dvdPrice = price;
	} //end method setdvdPrice

	//return DVD Price
	public double getDvdPrice() {
		return dvdPrice;
	} //end  method get Dvd Price

	//calculate inventory value
	public double value() {
		return dvdPrice * dvdStock;
	} //end method value

	public String toString() {
		return String.format("item=%3d rating=%-20s  title=%-20s   units=%3d   price=$%6.2f   value=$%7.2f",
							  dvdItem,dvdRating, dvdTitle, dvdStock, dvdPrice, value());
	}

} //end class DVD

class Movie extends DVD {
	private String movieTitle;

	public Movie(String title, int item, String dtitle, int stock, double price) {
		super(item, dtitle,  stock, price);
		movieTitle = title;
	}

	public double value() {
		double value = getDvdPrice() * getDvdStock();
		value = 1.05 * value;
		return value;
	} //end method value

	public String toString() {
		String s = String.format("Movie title=%-12s", movieTitle);
		s = s + " " + super.toString();
		return s;
	}

} // end class Movie



class Inventory.1 {
	private DVD[] dvds;
	private int count;

	Inventory() {
		dvds = new DVD[10];
		count = 0;
	}

	public void add(DVD dvd) {
		dvds[count] = dvd;
		++count;
		sort();
	}

	public double entireValue() {
		double value = 0;
		for (int i = 0; i < count; i++) {
			value = value + dvds[i].value();
		}
		return value;
	}

	public void sort() {
		for (int index = 1; index < count; index++) {
			DVD key = dvds[index];
			int position = index;

			//  Shift larger values to the right
			while (position > 0 && key.getDvdTitle().compareTo(dvds[position-1].getDvdTitle()) < 0) {
				dvds[position] = dvds[position-1];
				position--;
			}
			dvds[position] = key;
		}
	}

	public void display() {
		System.out.println("\nThe inventory contains " + count + " DVDs\n");
		for (int i = 0; i < count; i++)
			System.out.printf("%3d  %s\n", i, dvds[i]);
		System.out.printf("\nThe total inventory value is $%.2f\n\n", entireValue());
	}

} // end class Inventory
import java.io.*;
import java.text.*;
 import javax.swing.JFrame;
 
public class testInventory {
	 public static void main(String args[]){
		  // Create an inventory object
//		  Inventory inv = new Inventory();
 
  DVD[] DVDs = new DVD[3];
 


  //populate the array
  DVDs[0] = new DVD(3, "Gladiator DVD", 3, 15.99, 2000);
  DVDs[1] = new DVD(4, "Superman DVD", 10, 17.99, 2006);
  DVDs[2] = new DVD(5, "Batman DVD", 5, 18.99, 2006);
 
  //initiate decimal format object
  DecimalFormat Currency = new DecimalFormat("#0.00");
 
  //print the inventory information
  System.out.print("\nInventory of DVD Movies:\n\n");
  for(int i = 0; i < DVDs.length; i++)
  {
   DVD aDVD = DVDs;
 
  System.out.print("DVD Title:		 " + aDVD.getName() + "\n");
  System.out.print("Rating:			" + aDVD.getRating() + "\n");
  System.out.print("Number in stock:   " + aDVD.getQuantityOnHand() + "\n");
  System.out.print("Price:			 $" + Currency.format(aDVD.getPrice()) + "\n");
  System.out.print("Restocking fee(5%):$" + Currency.format(aDVD.getRestockinkingFee()) + "\n");
  System.out.print("Inventory Value:   $" + Currency.format(aDVD.getItemValue()) + "\n\n");
  System.out.print( "\n" );
  }
 

	 }
}
class SimpleFrame extends JFrame{
	public SimpleFrame(){
		super("Josh's Inventory");
		setSize(300,100);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	}
	public static void main(String[] arguments) {
		SimpleFrame sf = new SimpleFrame();
	}
}
class LabelFram extends JFrame
{
	private JLabel label1;
	private JLabel label2;
	
	public LabelFrame()
	{
		super("Testing JLabel");
		setLayout( new FlowLayout() );
		
		//JLabel constructor with a string argument
		label1=new JLabel("Inventory Item");
		label1.setToolTipText("This is label1");
		add(label1);
		
		label2=new Jlabel("Total Inventory");
		label1.setToolTipText("This is label2");
		add(label2);
		
	}//end LabelFram constructor
}//end class LabelFrame


thanks for any help anyone can give
I'm really struggling with this

Is This A Good Question/Topic? 0
  • +

Replies To: Inventory Program part 4

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Inventory Program part 4

Posted 06 April 2008 - 08:37 PM

You cannot have "." in a class name... it means it refers to a subClass of that class

dvdRating = rating;

the name of the parameter id devRating so

this.dvdRating = dvdRating; // or change the name of the parameter


public Movie(String title, int item, String dtitle, int stock, double price) {
super(item, dtitle, stock, price);

the constructor DVD(int, String, int, double) is undefined

the class name is LabelFram

public LabelFrame()

so the constructor should be

public LabelFram()


label2=new Jlabel("Total Inventory");

JLabel with a capital L
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1