Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Document1 - Word Sign in -0 × Insert Design Layout References Mailings Review Vi

ID: 3727910 • Letter: D

Question

Document1 - Word Sign in -0 × Insert Design Layout References Mailings Review View Help Tell me what you want to do Share File Home Cut Copy Fonmat Painter 1 AoBbCCD' · c Replace Paste :-. 11. Normal TNo Spac Heading 1 Hending 2 Title Subtitle Subtle Erm Emphasis ; Clipboard Font Paragraph Styles Editing Document Recovery Word has recovered the following files Save the ones you wish to keep. LAWS 1000V winter term ass Version created from the last... 3/9/2018 1:45 PM 1) Run the DVDCollectionApp program. You should see the following My DVD Colection LAWS 1000V winter term ass. Version created last time the... Year Length 9/2018 12:47 AM IFI Was aStudent 65 Don't Eat Your Pencil! 112 Tutornial Thoughts Fried Monitors 128 94 We will create a Dialog box that will allow us to enter information for a DVD to be added to the model The Dialog box is shown below in two snapshots. The first indicates the "prompt text-that will appear in the TextFields when no text has been entered. The second shows text that was entered Close Page 2 of 2 0 words + 100%

Explanation / Answer

package guiinventoryprogram;

import java.awt.GridLayout; // required to create a grid layout
import java.awt.BorderLayout; // required to create a border layout
import java.awt.event.ActionEvent; // required for click events
import java.awt.event.ActionListener; // required for click events
import javax.swing.JPanel; // required to create panels
import javax.swing.JFrame; // required to use the frame
import javax.swing.JButton; // required to create buttons
import javax.swing.JLabel; // required to create text fields
import javax.swing.JTextField; // required to create text fields
import java.util.Arrays; // required to sort array
import java.text.DecimalFormat;
public class GUIInventoryProgram extends JFrame implements ActionListener
{
// Declare Class Variables   
//Declare two panels. gridPanel is main panel. panel is inserted into gridPanel.
private JPanel gridPanel = new JPanel(); // one panel that contains my gridlayout.
private JPanel panel = new JPanel(); // panel used to contain buttons, labels and text fields
// Declare buttons
JButton nextButton; // first button
// Declare Text Fields
JTextField TitleField; // Dvd Title
JTextField UnitsField; // Units Field
JTextField ItemNumberField; // Item Number field
JTextField PriceField; // Dvd Price field
JTextField ValueField; // Value field
  
JTextField DirectorField;
  
// Declare Labels
JLabel lblTitle; // Title label
JLabel lblUnits; // Units Label
JLabel lblItemNumber; // Item Number label
JLabel lblPrice; // Price Label
JLabel lblValue; // Value of DVDs Label
  
JLabel lblDirector;
// Declare 5 Dvd Objecs
Dvd dvd1;
Dvd dvd2;
Dvd dvd3;
Dvd dvd4;
Dvd dvd5;
  
private static final int MAX_dvds = 5; // set maximum size for DVD Array
Dvd[] dvd = new Dvd[MAX_dvds]; // create Dvd Array object
  
DecimalFormat formatter = new DecimalFormat("$##,###.00");
  
private static DecimalFormat currency = new DecimalFormat("$#,##0.00");
private static int ArrayIndex = 0; // array index
public GUIInventoryProgram() // constructor
{
MovieDirector d1 = new MovieDirector("Transformers", 7, 1002, 19.98, "Michael Bay");
// Creates an instance of the DVD class and initialize class instance variables
MovieDirector d2 = new MovieDirector("Green Mile", 3, 542, 14.50, "Frank Darabont");
// Creates an instance of the DVD class and initialize class instance variables
MovieDirector d3 = new MovieDirector("Lord of the Rings", 5, 937, 24.98, "Peter Jackson");
// Creates an instance of the DVD class and initialize class instance variables
MovieDirector d4 = new MovieDirector("Jar Head", 2, 865, 9.75, "Sam Mendes");
// Creates an instance of the DVD class and initialize class instance variables
MovieDirector d5 = new MovieDirector("Inception", 6, 1157, 21.97, "Christopher Nolan");
// Creates an instance of the DVD class and initialize class instance variables
  
// adding Dvd objects to the array
dvd[0] = d1; // adding Transformers to the array of dvds
dvd[1] = d2; // adding Green Mile to the array of dvds
dvd[2] = d3; // adding Lord of the Rings to the array of dvds
dvd[3] = d4; // adding Jar Head to the array of dvds
dvd[4] = d5; // adding Inception to the array of dvds
  
Dvd.sortByTitle(dvd); // sort the array by name of title
gridPanel.setLayout(new BorderLayout()); // create a border layout
gridPanel.add(this.createLabelPanel(), BorderLayout.WEST); // add label panel
gridPanel.add(this.createTextPanel(), BorderLayout.CENTER); // add field panel
gridPanel.add(this.createButtonPanel(), BorderLayout.SOUTH); // add button panel
add(gridPanel);
}

// helper method creates a panel for the button
private JPanel createButtonPanel()
{
// ActionListener btnListen = new ButtonListener(); // create listener
// create button objects
nextButton = new JButton("Display DVD Information"); // create and label button
nextButton.setActionCommand("Next"); // action command for click button event
  
// nextButton.addActionListener(btnListen); // button listener for click button event
nextButton.addActionListener(this);
// create panel object
JPanel pobj = new JPanel();
pobj.add(nextButton); // add next button to panel
return pobj; // return panel
} // end createButtonPanel method
private JPanel createLabelPanel()
{
// create instance of label objects
lblTitle = new JLabel("Title:"); // label for Title of DVD
lblUnits = new JLabel("Units:"); // label for Units in stock for DVD
lblItemNumber = new JLabel("Item Number:"); // label for DVD Item Number
lblPrice = new JLabel("Price:"); // label for price of DVD
lblValue = new JLabel("Value of Items:"); // lable for value of DVD
  
lblDirector = new JLabel ("Directors Name:");
panel = new JPanel();
panel.setLayout(new GridLayout(6, 1));
// add labels to the panel
panel.add(lblTitle);
panel.add(lblUnits);
panel.add(lblItemNumber);
panel.add(lblPrice);
panel.add(lblValue);
  
panel.add(lblDirector);
return panel;
} // end createLabelPanel method
private JPanel createTextPanel()
{
//create instances of text box objects
TitleField = new JTextField(); // Title text field
TitleField.setEditable(false); // set field to not editable to prevent user from changing the data
UnitsField = new JTextField(); // Units text field
UnitsField.setEditable(false); // set field to not editable to prevent user from changing the data
ItemNumberField = new JTextField(); // Item Number field
ItemNumberField.setEditable(false); // set field to not editable to prevent user from changing the data
PriceField = new JTextField(); // Price text field
PriceField.setEditable(false); // set field to not editable to prevent user from changing the data
ValueField = new JTextField(); // Value text field to sum the total of the DVDs value.
ValueField.setEditable(false); // set field to not editable to prevent user from changing the data
  
DirectorField = new JTextField();
  
DirectorField.setEditable(false);
panel = new JPanel(); // create panel object
panel.setLayout(new GridLayout(6, 1)); // create grid layout for fields.
panel.add(TitleField); // add the Title field to the grid layout
panel.add(UnitsField); // add the Units field to the grid layout
panel.add(ItemNumberField); // add the Item Number field to the grid layout
panel.add(PriceField); // add the Price field to the grid layout
panel.add(ValueField); // add the total value field to the grid layout
  
panel.add(DirectorField);
return panel; // return the panel
} // end createTextPanel method

@ Override public void actionPerformed(ActionEvent e)
{
// add button functions
if ("Next".equals(e.getActionCommand()))
if (ArrayIndex < dvd.length)
{
TitleField.setText(dvd[ArrayIndex].getDvdTitle()); // get the Dvds title
// and assign it the name text field.
UnitsField.setText(String.valueOf(dvd[ArrayIndex].getDvdUnits()));
// get the units in stock and assign it the Units text field.
ItemNumberField.setText(String.valueOf(dvd[ArrayIndex].getDvdItemNumber()));
// get Dvds item number and assign it the item number text field.   
  
PriceField.setText(String.format("$ %8.2f", dvd[ArrayIndex].getDvdPrice()));
// get the Price of the DVD and assign it the price text field.
ValueField.setText(String.format("$ %8.2f", dvd[ArrayIndex].getDvdValue()));  
// display the sum of the total of the DVDs in stock
  
DirectorField.setText(String.valueOf(dvd[ArrayIndex].getdvdDirector()));
// display the Directors name of the DVD
ArrayIndex = ArrayIndex + 1; // increment the array index to get to the next value
} // end if
} // end actionPerformed
public static void main(String[] args)
{
JFrame frame = new GUIInventoryProgram(); // creat a frame object
frame.setSize(400, 300); // set the size of the window - 400 is width, 200 is height
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // close the application
frame.setTitle("DVD Inventory"); // set the title of the window
frame.setLocationRelativeTo( null ); // center the form
frame.setVisible(true); // display form
} // end main

} // end GUIInventoryProgram class


package guiinventoryprogram;
class Dvd {
// declare instance variables
private String dvdTitle; //title of dvd
private int dvdUnits; // number of units of the dvd
private double dvdItemNumber; // item number of the dvd
private double dvdPrice; // Price of the dvd
private String dvdDirector;
public Dvd()
{
}
//declare DVD constructor that shows title, stock, item, and price
public Dvd(String Title, int Units, double ItemNumber, double Price, String Director) {
//call to Object constructor occurs here
dvdTitle = Title;
dvdUnits = Units;
dvdItemNumber = ItemNumber;
dvdPrice = Price;
dvdDirector = Director;
  
} //end four-argument constructor
  
//set DVD name
public void setdvdTitle(String Title) {
setdvdTitle(Title);
} //end method setDvdTitle
//return dvd Title
public String getDvdTitle() {
return dvdTitle;
} //end method getDvdTitle
//set Dvd stock
public void setDvdUnits(int Units) {
dvdUnits = (Units < 0) ? 0 : Units;
} //end method setDvdStock
//return dvd stock
public double getDvdUnits() {
return dvdUnits;
} //end method getDvdStock
public void setDvdItemNumber(double ItemNumber) {
dvdItemNumber = (ItemNumber < 0.0) ? 0.0 : ItemNumber;
} //end method set dvd Item
//return dvd item
public double getDvdItemNumber() {
return dvdItemNumber;
} //end method getDvdItem
public void setDvdPrice(double Price) {
dvdPrice = (Price < 0.0) ? 0.0 : Price;
} //end method SetDvdPrice
//return dvd price
public double getDvdPrice() {
return dvdPrice;
} //end method get Dvd Price
// calculate inventory value
public double getDvdValue() {
return getDvdPrice() * dvdUnits;
} //end method value
  
public double getdvdRestockingfee() {
return getDvdValue() * .05;
}
  
public void setdvdDirector(String Director) {
setdvdDirector(Director);
} //end method setDvdTitle
//return dvd Title
public String getdvdDirector() {
return dvdDirector;
} //end method getDvdTitle
  
public static void sortByTitle(Dvd dvd[])
{ // sort the dvd by title
Dvd temp;
for(double j = dvd.length - 2; j >= 0; j--)
for(int i = 0 ; i <= j ; i++)
if(dvd [ i ].getDvdTitle().compareTo(dvd[ i + 1 ].getDvdTitle())>0)
{
temp=dvd[ i ];
dvd[ i ] = dvd[ i + 1 ];
dvd[ i + 1 ] = temp;
}
} // end sort by title method
} // end class dvd


package guiinventoryprogram;
class MovieDirector extends Dvd{
private String Director;
private double Restockingfee;
  
public MovieDirector(String Title, int Units, double ItemNumber, double Price, String Director)
{
super(Title, Units, ItemNumber, Price);
this.Director=Director;
this.Restockingfee = Restockingfee;
  
}
public String getDirector() {
return Director;
}
public void setDirector(String Director) {
this.Director = Director;
}
  
public double getRestockingfee() {
return getDvdValue() * 0.05;
}   
public void setRestockingfee (double Restockingfee){
this.Restockingfee = Restockingfee;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote