import java.util.Scanner;
import java.util.Arrays;
import java.lang.String;
import static java.lang.System.out;
import javax.swing.*;
import java.awt.event.*;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
// all imports for program
public class InventoryProgram
{
// main method begins program execution
public static void main(String args[] )
{
// display a welcome message to the InventoryProgram to user
System.out.println( "Welcome to Inventory Program!" );
//Supplies[] supplies = new Supplies[100]; // an array of 100 supplies
/***
* Use Child class array
*/
Manufacturer[] supplies = new Manufacturer[5]; // an array of 100 supplies
/*
- USE AN ARRAY OF CHILD OBJECTS AS SHOWN BELOW
Supplies Maverick = new Supplies( 001, "Maverick", 60, 2.75 );
Supplies Termidor = new Supplies( 002, "Termidor", 75, 1.25 );
Supplies Bithor = new Supplies( 003, "Bithor", 30, 4.75 );
Supplies Demon = new Supplies( 004, "Demon", 15, 5.25 );
Supplies DeltaDust = new Supplies( 005, "Delta Dust", 45, 3.50 );
*/
//Adding Child objects to the array
supplies[0] = new Manufacturer( 001, "Maverick", 60, 2.75, "Univar inc." );
supplies[1] = new Manufacturer( 002, "Termidor", 75, 1.25, "Dupont" );
supplies[2] = new Manufacturer( 003, "Bithor", 30, 4.75, "Bayer" );
supplies[3] = new Manufacturer( 004, "Demon", 15, 5.25, "Dow Chemicals" );
supplies[4] = new Manufacturer( 005, "Delta Dust", 45, 3.50, "Ipsothor" );
// display the inventories one at a time
/*
Maverick.showInventory();
Termidor.showInventory();
Bithor.showInventory();
Demon.showInventory();
DeltaDust.showInventory();
*/
//OUTPUT ITEMS FROM ARRAY
for(int i = 0; i < supplies.length; ++i){
supplies[i].showInventory();
}
NewJFrame gui = new NewJFrame(); //Call GUI
gui.addData(supplies); //Passing Data to the GUI
} // end method main
} // end class InventoryProgram
// Office Supplies
class Supplies
{
private int SuppliesNumber;
private String SuppliesName = new String();
private int SuppliesUnits;
private double SuppliesPrice;
// set supplies number
public void setSuppliesNumber( int number )
{
this.SuppliesNumber = number;
} // end method set supplies number
// return supplies number
public float getSuppliesNumber()
{
return SuppliesNumber;
} // end method get supplies number
// set supplies name
public void setSuppliesName( String name )
{
this.SuppliesName = name;
} // end method set supplies name
// return supplies name
public String getSuppliesName()
{
return SuppliesName;
} // end method get supplies name
// set supplies in stock
public void setSuppliesUnits( int units )
{
this.SuppliesUnits = units;
} // end method set supplies units
// return supplies units
public int getSuppliesUnits()
{
return SuppliesUnits;
} // end method get supplies units
// set supplies price
public void setSuppliesPrice( double price )
{
this.SuppliesPrice = price;
} // end method set supplies price
// return supplies price
public double getSuppliesPrice()
{
return SuppliesPrice;
} // end method get supplies price
// calculate supplies inventory value
public double getValue()
{
return SuppliesUnits * SuppliesPrice;
} // end method supplies inventory value
// four-argument constructor
Supplies( int number, String name, int units, double price )
{
SuppliesNumber = number;
SuppliesName = name;
SuppliesUnits = units;
SuppliesPrice = price;
} // end four-argument constructor
// display inventory
public void showInventory()
{
System.out.println(); // outputs blank line
System.out.println( "Product Number: "+SuppliesNumber );
System.out.println( "Product Name: "+SuppliesName );
System.out.println( "Number of Units: "+SuppliesUnits );
System.out.printf( "Unit Price: $%.2f", SuppliesPrice );
// value() method and display the value
System.out.printf( "\nInventory value of "+SuppliesName+ " is = $%.2f\n",
getValue() );
} // end display inventory
//return String representation of suppliesManufacturer
public String toString()
{
String formatString = String.format("Product Number: %d \n", SuppliesNumber);
formatString += String.format("Product Name: %s \n", SuppliesName);
formatString += String.format("Number of Units: %d \n", SuppliesUnits);
formatString += String.format("Units Price: $%.2f \n", SuppliesPrice);
return( formatString);
} // end toString()
} // end class supplies
class Manufacturer extends Supplies
{
// holds the supplies manufacturer
private String suppliesManufacturer;
// five-argument constructor
Manufacturer( int number, String name, int units, double price, String manufacturer )
{
super( number, name, units, price );
suppliesManufacturer = manufacturer;
} // end five-argument constructor
// set supplies manufacturer
public void setManufacturer( String manufacturer )
{
this.suppliesManufacturer = manufacturer;
} // end method set supplies manufacturer
// return supplies manufacturer
public String getManufacturer()
{
return suppliesManufacturer;
} // end method get supplies manufacturer
// add 5% restocking fee
public double getValue()
{
return super.getValue() * 1.05;
} // end method return supplies manufacturer
// calculate restocking fee
public double getRestockingFee()
{
return super.getValue() * .05;
} //end method calculate restocking fee
//return String representation of suppliesManufacturer
public String toString()
{
String formatString = super.toString();
formatString += "Manufacturer: %s \n";
formatString += "Restocking Fee: $%.2f \n";
formatString += "Inventory Value: $%.2f \n";
formatString = String.format( formatString, suppliesManufacturer,
getRestockingFee(), getValue());
return( formatString);
} // end toString()
// display inventory
public void showInventory()
{
super.showInventory();
System.out.println( toString() );
} // end method display inventory
}// end class manufacturer
// Start of GUI class
class NewJFrame extends javax.swing.JFrame {
private JTextArea area; //Define Needed Objects and Variables
private JButton next;
private static int count = 0;
//Keep track of current item which helps with button logic
private JButton back;
private JButton first;
private JButton last;
private Manufacturer[] info; //Declare Array
//Constructor that runs when object is created
public NewJFrame()
{
setTitle("GUI"); //Set GUI Title
JPanel panel = new JPanel(); //Use JPanel to hold ifo
area = new JTextArea(12, 20); //Set JTextArea Size
panel.add(area); //Add to JPanel
next = new JButton("Next"); //create JButton
back = new JButton("Back");
first = new JButton("First");
last = new JButton ("Last");
// creates all buttons.
panel.add(next); //Add Button to JPanel
add(panel); //Add JPanel to JFrame
panel.add(back);
add(panel);
panel.add(first);
add(panel);
panel.add(last);
add(panel);
//adds the JPanels to JFrame for buttons.
ButtonHandler handler = new ButtonHandler();
//Create Button Handler Object
next.addActionListener(handler);
back.addActionListener(handler);
first.addActionListener(handler); // THESE TWO ARE NOT WORKING!!!!
last.addActionListener(handler); //SEE ABOVE NOTE
//Add Action Listener for JButton to Handler
setSize(375, 275); // Set JFrame Size
setDefaultCloseOperation(EXIT_ON_CLOSE); // Default Operation on Close
setLocationRelativeTo(null); //Center On Desktop
setVisible(true); // Allow JFrame to be seen
} //End Constructor
//Nested Class Handler for Button Clicks
private class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent event) //Check Action
{
String text = (String)event.getActionCommand();
//Get Text From Button
if (event.getSource() == next)
//Check Button Source
{
//Check count to determine if increment to next item is desired
++count;
if (count == info.length) // "Next Item" until last
{
count = 0;
} //end if
} //end if / else
if (event.getSource() == back)
{
--count;
if (count == info.length)
{
count = 0;
}
}
if (event.getSource() == first)
{
count=0;
}
if (event.getSource() == last)
{
count=4;
}
updateView(); //Update View to next item
} //End Method
} //end nested class
public void updateView() //Update info to JTextArea of GUI
{
//Set data for viewing in the JTextArea area
area.setText("Item: \n\n");
area.append(info[count].toString());
//Call toString information
}
//Reassign Array Created in main method to info Array
public void addData(Manufacturer[] manuf)
{
info = manuf; //set info array to passed mi array
count = 0; //ensure count is on 1st item of array
updateView(); //Show 1st Item by updating view
}
}
class Logo extends JPanel {
public Logo() {
super();
setPreferredSize(new Dimension(200,200));
}
public void paint(Graphics g) {
g.setColor(Color.red);
g.fillRoundRect(60,60,110,90,5,5);
g.setColor(Color.black);
g.drawString("DEAD BUG", 70, 105);
}
}