Inventory Part 4 GUI

Modify the Inventory Program to use a GUI.

Page 1 of 1

4 Replies - 2876 Views - Last Post: 20 July 2009 - 10:06 AM Rate Topic: -----

#1 Beachgirl029  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 07-July 09

Inventory Part 4 GUI

Posted 20 July 2009 - 09:04 AM

I need your help. I am in the Inventory part 4, and I do not know where to begin. I have never experimented with GUI, I need help with a good explanation of where to start. My program up to this point is running GREAT. I am not sure how to start this current modification. Thank you for any advice you can give me.

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.

package InventoryProgram;

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

		Product dvd = new Product ("Bye Bye Love", 1, 19.99, 3);
		System.out.println(dvd);

		dvd = new Product ("Fireside Rflections", 2, 12.99, 5);
		System.out.println(dvd);

		dvd = new Product ("Green Mile", 3, 24.99, 2);
		System.out.println(dvd);

		dvd = new Product ("Titanic", 4, 30.00, 10);
		System.out.println(dvd);

		System.out.println("Product Title is: " + dvd.getDvdTitle());
		System.out.println(" The item number is: " + dvd.getDvdItemNumber());
		System.out.println("The price of each DVD is $ " + dvd.getDvdPrice());
		System.out.println(" The number of units in stock is: "
				+ dvd.getDvdStockNumber());
	}//end main class
}//end Inventory Program Part 1

package inventoryprogram;

import InventoryProgram.Product;

public class DVD extends Product {
 //Inherites class DVD from the base class Product, the extra feature is having 
//a year the movie was made.
	private int movieyear;
	//Holds the year the movie was made

	public DVD(String title, int itemNumber, double price, int stockNumber, int year){
		//Constructor to call the Product constructor.
		super (title, itemNumber, price, stockNumber);
		movieyear = year;
	}
	public void setYear(int year){
		//Sets year
		movieyear = year;
	}
	public int getYear(){//get the year of the DVD product
		return movieyear;
	}
	public double getValue(){
		return super.Value()* 1.05;
	}//Overrides Value() in Product class by calling the base class and adding a
	//5% restocking fee on top

	public double getRestockingFee() {
		return super.Value() * .05;
	}//gets the base class value and figures out the restocking fee only
}

package InventoryProgram;

import java.text.DecimalFormat;
//Import the format class to format values into currency format
public class Inventory {

	int inventorySize = 30;
	//This sets the Array to hold "30" items
	private Product items [] = new Product [inventorySize];

	DecimalFormat formatter = new DecimalFormat ("$##,###.00");
	//Sets the formatter to format values into currency form

	public void addDVD (Product item){
		for (int i =0; i< inventorySize; i++){
			if (items [i] == null){
				items [i] = item;
				return;
			}
		}
	}

	 // Loops through the array of products and adds up the total value.
	// Adds the value to a running total accumulator variable.

	public double getTotalInvValue(){
		double Value = 0.0;

	//Uses a comndensed for loop that iterates the array of items.
		for (Product item : items){
			if (item != null){
				Value += item.getDvdPrice();
			}
		}
		return Value;
	}
	//Prints the inventory list including name, quantity, price and total stock
	//value for each item.

	public void printInventory(){
		System.out.println("Printing items in inventory...\n");

		boolean DVDItems = false;

		for (Product item : items){
			if (item != null){
				DVDItems = true;
				System.out.println(item.getDvdTitle() + "Quantity: " 
						+ item.Value() + "Value of Stock: "
						+ formatter.format(item.Value()));
			}
		}
	}
}[code]
package InventoryProgram;
 public class Main {
Public static void main(String[] args) {
Poduct dvd = new Product ("Bye Bye Love", 1, 19.99, 3);
System.out.println(dvd);
dvd = new Product ("Fireside Rflections", 2, 12.99, 5);
System.out.println(dvd);
dvd = new Product ("Green Mile", 3, 24.99, 2);
System.out.println(dvd);
dvd = new Product ("Titanic", 4, 30.00, 10);
System.out.println(dvd);
System.out.println("Product Title is: " + dvd.getDvdTitle());
System.out.println(" The item number is: " + dvd.getDvdItemNumber());
System.out.println("The price of each DVD is $ " + dvd.getDvdPrice());
System.out.println(" The number of units in stock is: "+ dvd.getDvdStockNumber());
}//end main class
}//end Inventory Program Part 1  package inventoryprogram;
 import InventoryProgram.Product;
 public class DVD extends Product {
  //Inherites class DVD from the base class Product, the extra feature is having
 //a year the movie was made.
 	private int movieyear;
 	//Holds the year the movie was made
	  public DVD(String title, int itemNumber, double price, int stockNumber, int year){
 		//Constructor to call the Product constructor.
 		super (title, itemNumber, price, stockNumber);
 		movieyear = year;
 	}
 	public void setYear(int year){
 		//Sets year
 		movieyear = year;
 	} 	
public int getYear(){
//get the year of the DVD product
 		return movieyear;
 	}
 	public double getValue(){
 		return super.Value()* 1.05;
 	}
//Overrides Value() in Product class by calling the base class and adding a
 	//5% restocking fee on top
	  public double getRestockingFee() {
 		return super.Value() * .05;
 	}
//gets the base class value and figures out the restocking fee only }
  package InventoryProgram;
  import java.text.DecimalFormat;
 //Import the format class to format values into currency format public class Inventory
 {
	  int inventorySize = 30;
 	//This sets the Array to hold "30" items
 	private Product items [] = new Product [inventorySize];
	  DecimalFormat formatter = new DecimalFormat ("$##,###.00");
 	//Sets the formatter to format values into currency form
	  public void addDVD (Product item){
 		for (int i =0; i< inventorySize; i++){
 			if (items [i] == null){
 				items [i] = item;
 				return;
 			}
 		}
 	}
	   // Loops through the array of products and adds up the total value.
 	// Adds the value to a running total accumulator variable.
	  public double getTotalInvValue(){
 		double Value = 0.0;
	  //Uses a comndensed for loop that iterates the array of items.
 		for (Product item : items){
 			if (item != null){
 				Value += item.getDvdPrice();
 			}
 		}
 		return Value;
 	}
 	//Prints the inventory list including name, quantity, price and total stock
 	//value for each item.
	  public void printInventory(){
 		System.out.println("Printing items in inventory...\n");
		  boolean DVDItems = false;
		  for (Product item : items){
 			if (item != null){
 				DVDItems = true;
 				System.out.println(item.getDvdTitle() + "Quantity: + item.Value() + "Value of Stock: " + formatter.format(item.Value()));
 			}
 		}
 	}
 }


This post has been edited by Beachgirl029: 20 July 2009 - 09:26 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Inventory Part 4 GUI

#2 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Inventory Part 4 GUI

Posted 20 July 2009 - 09:16 AM

forgot the end code tag
:code:
If you have never experimented with GUI before the best thing to do right now wouldbe to learn some of the basics of GUI.

Good tutorial.
Sun TUtorial - With this one DO NOT choose the Netbeans IDE. That will not help you at all.

Have a go at it and if you have specific question or errors post them and we would be glad to help. Having no experience with GUI before it is kind of hard to point you in the right direction, so maybe this will help first.

Hope this helps!

This post has been edited by Fuzzyness: 20 July 2009 - 09:16 AM

Was This Post Helpful? 0
  • +
  • -

#3 Beachgirl029  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 07-July 09

Re: Inventory Part 4 GUI

Posted 20 July 2009 - 09:35 AM

I am using Netbeans and this is why I am so confused. Am I supposed to chose a new file? and chose a GUI method? If yes then I have 2 to chose from "Swing GUI Forms" and "AWT GUI Forms" I do not know how to begin. My Instructor can not give me help, because she said she does not use Netbeans and is not familiar with it.

View PostFuzzyness, on 20 Jul, 2009 - 08:16 AM, said:

forgot the end code tag
:code:
If you have never experimented with GUI before the best thing to do right now wouldbe to learn some of the basics of GUI.

Good tutorial.
Sun TUtorial - With this one DO NOT choose the Netbeans IDE. That will not help you at all.

Have a go at it and if you have specific question or errors post them and we would be glad to help. Having no experience with GUI before it is kind of hard to point you in the right direction, so maybe this will help first.

Hope this helps!

Was This Post Helpful? 0
  • +
  • -

#4 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Inventory Part 4 GUI

Posted 20 July 2009 - 09:39 AM

NetBeans is a Drag and Drop GUI Wizard. It is bad practiceto use NetBeans if you do not know how to hard code java GUI. I would see get one of the free programs like JCreator LE or I kow some people like to use Eclipse. I use JCreator LE and it is a wonderful program easy to use. I will only use netBeans when I need a quick form made, but I already know how to hard code java GUI. I would suggest looking at those 2 links I gave you and also looking into a IDe like JCreator or Eclipse. If you absolutely feel like using NetBeans, in the Sun TUtorial Link I gave you the 2nd Option on GUI is using Netbeans.
Was This Post Helpful? 0
  • +
  • -

#6 NeoTifa  Icon User is offline

  • ¿Dónde están mis pantalones?
  • member icon





Reputation: 1973
  • View blog
  • Posts: 14,489
  • Joined: 24-September 08

Re: Inventory Part 4 GUI

Posted 20 July 2009 - 10:06 AM

I use NetBeans, and I can honestly say I took one look at the DnD GUI builder, and my head exploded. Just make a class to extend JFrame, set the size, title, and visibity. Then have another for your JPanel, and add JButtons, JComboBoxes, etc. to it. Add the panel to the frame and voila! ^_^ Not that hard really. I hard code all my GUI. In the DnD they make a bunch of random names that get really confusing. Plus, if you do it this way, you feel like you have more control
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1