I am trying to get my program to compile but its not quite working like it did before I emailed it from my work. Can someone maybe catch the problem for me?
CODE
package com.inahurry.ageCalulator;
import javax.swing.*;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
public class AgeCalculatorUI extends JPanel implements ActionListener{
private static final String ALCOHOL = "Alcohol";
private static final String PG_13_MOVIE = "Movie, PG-13 Rated";
private static final String R_MOVIE = "Movie, R Rated";
private static final String T_GAME = "Video Game, T Rated";
private static final String TOBACCO = "Tobacco";
private static final String[] PRODUCTS_LIST = new String[]{"",
ALCOHOL,
PG_13_MOVIE,
R_MOVIE,
TOBACCO,
T_GAME};
private SimpleDateFormat smplDateFormat = new SimpleDateFormat("MM/dd/yyyy");
private JLabel customerBirthdaylabel;
private JLabel productLabel;
private JTextField customerBirthdayText;
private JComboBox productMenu;
private JButton validateBtn;
public AgeCalculatorUI() {
//Add the label and textbox for the customer birth date.
customerBirthdaylabel = new JLabel("Please enter the customer's date of birth (DOB):");
customerBirthdayText = new JTextField(12);
JPanel dataEntryPanelTop = new JPanel();
dataEntryPanelTop.setLayout(new BoxLayout(dataEntryPanelTop, BoxLayout.LINE_AXIS));
dataEntryPanelTop.add(Box.createRigidArea(new Dimension(15, 0)));
dataEntryPanelTop.add(customerBirthdaylabel);
dataEntryPanelTop.add(Box.createRigidArea(new Dimension(15, 0)));
dataEntryPanelTop.add(customerBirthdayText);
dataEntryPanelTop.add(Box.createRigidArea(new Dimension(15, 0)));
//Add the label and menu for the product selected for purchase.
productLabel = new JLabel("Please select the product being purchased:");
productMenu = new JComboBox(PRODUCTS_LIST);
JPanel dataEntryPanelBottom = new JPanel();
dataEntryPanelBottom.add(Box.createRigidArea(new Dimension(15, 0)));
dataEntryPanelBottom.setLayout(new BoxLayout(dataEntryPanelBottom, BoxLayout.LINE_AXIS));
dataEntryPanelBottom.add(productLabel);
dataEntryPanelBottom.add(Box.createRigidArea(new Dimension(15, 0)));
dataEntryPanelBottom.add(productMenu);
dataEntryPanelBottom.add(Box.createRigidArea(new Dimension(15, 0)));
//Add the button to verify whether to allow purchase or not.
validateBtn = new JButton("Check Age");
validateBtn.setAlignmentX(Component.CENTER_ALIGNMENT);
validateBtn.addActionListener(this);
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
buttonPanel.add(validateBtn);
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.PAGE_AXIS));
mainPanel.add(Box.createRigidArea(new Dimension(0, 15)));
mainPanel.add(dataEntryPanelTop, BorderLayout.EAST);
mainPanel.add(Box.createRigidArea(new Dimension(0, 15)));
mainPanel.add(dataEntryPanelBottom, BorderLayout.EAST);
mainPanel.add(Box.createRigidArea(new Dimension(0, 15)));
mainPanel.add(buttonPanel, BorderLayout.PAGE_END);
mainPanel.add(Box.createRigidArea(new Dimension(0, 15)));
add(mainPanel);
}
private void alertClerk(String message) {
JFrame frame = new JFrame("In a Hurry Stores: Age Check Utility");
JLabel messageToClerk = new JLabel(message);
frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.LINE_AXIS));
frame.getContentPane().add(messageToClerk);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public void actionPerformed(ActionEvent arg0) {
Date customerDOB = smplDateFormat.parse(customerBirthdayText.getText(), new java.text.ParsePosition(0));
String productType = productMenu.getSelectedItem().toString();
if ( customerDOB.equals("") || customerDOB == null) {
//Alert the clerk to enter valid DOB
alertClerk("Please enter a valid date for Customer Birthdate (mm/dd/yyyy).");
} else if (productType.equals("")) {
//Alert the clerk to enter product
alertClerk("Please select a Product from the list.");
} else if (productType.equals(ALCOHOL)) {
Alcohol alcProduct = new Alcohol(customerDOB);
if (alcProduct.isPurchaseAllowed()) {
//Alert the clerk that the purchase is allowed
alertClerk("OK. (This customer meets the age restriction.)");
} else {
//Alert the clerk that the purchase is allowed
alertClerk("RESTRICTED!! (This customer DOES NOT meet the age restriction!!)");
}
} else if (productType.equals(PG_13_MOVIE)) {
PG13Movie pg13Product = new PG13Movie(customerDOB);
if (pg13Product.isPurchaseAllowed()) {
//Alert the clerk that the purchase is allowed
alertClerk("OK. (This customer meets the age restriction.)");
} else {
//Alert the clerk that the purchase is allowed
alertClerk("RESTRICTED!! (This customer DOES NOT meet the age restriction!!)");
}
} else if (productType.equals(R_MOVIE)) {
RMovie rMovieProduct = new RMovie(customerDOB);
if (rMovieProduct.isPurchaseAllowed()) {
//Alert the clerk that the purchase is allowed
alertClerk("OK. (This customer meets the age restriction.)");
} else {
//Alert the clerk that the purchase is allowed
alertClerk("RESTRICTED!! (This customer DOES NOT meet the age restriction!!)");
}
} else if (productType.equals(T_GAME)) {
TGame tGameProduct = new TGame(customerDOB);
if (tGameProduct.isPurchaseAllowed()) {
//Alert the clerk that the purchase is allowed
alertClerk("OK. (This customer meets the age restriction.)");
} else {
//Alert the clerk that the purchase is allowed
alertClerk("RESTRICTED!! (This customer DOES NOT meet the age restriction!!)");
}
} else if (productType.equals(TOBACCO)) {
Tobacco tobaccoProduct = new Tobacco(customerDOB);
if (tobaccoProduct.isPurchaseAllowed()) {
//Alert the clerk that the purchase is allowed
alertClerk("OK. (This customer meets the age restriction.)");
} else {
//Alert the clerk that the purchase is allowed
alertClerk("RESTRICTED!! (This customer DOES NOT meet the age restriction!!)");
}
}
}
/**
* Create the UI and show it.
*/
private static void createAndShowAgeCalculatorUI() {
//Create and set up the window.
JFrame frame = new JFrame("In a Hurry Stores: Age Check Utility");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
AgeCalculatorUI newContentPane = new AgeCalculatorUI();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowAgeCalculatorUI();
}
});
}
}
my error code is as follows
CODE
C:\Users\Brian\AppData\Local\Temp\Rar$DI04.407\AgeCalculatorUI.java:111: cannot find symbol
symbol : class Alcohol
location: class com.inahurry.ageCalulator.AgeCalculatorUI
Alcohol alcProduct = new Alcohol(customerDOB);
^
C:\Users\Brian\AppData\Local\Temp\Rar$DI04.407\AgeCalculatorUI.java:111: cannot find symbol
symbol : class Alcohol
location: class com.inahurry.ageCalulator.AgeCalculatorUI
Alcohol alcProduct = new Alcohol(customerDOB);
^
C:\Users\Brian\AppData\Local\Temp\Rar$DI04.407\AgeCalculatorUI.java:124: cannot find symbol
symbol : class PG13Movie
location: class com.inahurry.ageCalulator.AgeCalculatorUI
PG13Movie pg13Product = new PG13Movie(customerDOB);
^
C:\Users\Brian\AppData\Local\Temp\Rar$DI04.407\AgeCalculatorUI.java:124: cannot find symbol
symbol : class PG13Movie
location: class com.inahurry.ageCalulator.AgeCalculatorUI
PG13Movie pg13Product = new PG13Movie(customerDOB);
^
C:\Users\Brian\AppData\Local\Temp\Rar$DI04.407\AgeCalculatorUI.java:136: cannot find symbol
symbol : class RMovie
location: class com.inahurry.ageCalulator.AgeCalculatorUI
RMovie rMovieProduct = new RMovie(customerDOB);
^
C:\Users\Brian\AppData\Local\Temp\Rar$DI04.407\AgeCalculatorUI.java:136: cannot find symbol
symbol : class RMovie
location: class com.inahurry.ageCalulator.AgeCalculatorUI
RMovie rMovieProduct = new RMovie(customerDOB);
^
C:\Users\Brian\AppData\Local\Temp\Rar$DI04.407\AgeCalculatorUI.java:148: cannot find symbol
symbol : class TGame
location: class com.inahurry.ageCalulator.AgeCalculatorUI
TGame tGameProduct = new TGame(customerDOB);
^
C:\Users\Brian\AppData\Local\Temp\Rar$DI04.407\AgeCalculatorUI.java:148: cannot find symbol
symbol : class TGame
location: class com.inahurry.ageCalulator.AgeCalculatorUI
TGame tGameProduct = new TGame(customerDOB);
^
C:\Users\Brian\AppData\Local\Temp\Rar$DI04.407\AgeCalculatorUI.java:160: cannot find symbol
symbol : class Tobacco
location: class com.inahurry.ageCalulator.AgeCalculatorUI
Tobacco tobaccoProduct = new Tobacco(customerDOB);
^
C:\Users\Brian\AppData\Local\Temp\Rar$DI04.407\AgeCalculatorUI.java:160: cannot find symbol
symbol : class Tobacco
location: class com.inahurry.ageCalulator.AgeCalculatorUI
Tobacco tobaccoProduct = new Tobacco(customerDOB);
I do have subclasses but they wont compile anymore either??
CODE
package com.inahurry.ageCalulator;
import java.util.Calendar;
import java.util.Date;
public class Alcohol extends RestrictedProduct {
private static final int REQUIRED_AGE = 21;
// Constructors that call the base class constructors
public Alcohol() {
super();
}
public Alcohol(Date DOB) {
super(DOB);
}
//Utilize the base class isPurchaseAllowed by passing it the required age
public boolean isPurchaseAllowed() {
return super.isPurchaseAllowed(REQUIRED_AGE);
}
}
Does anyone know what I might be missing?? Any guidance is greatly appreciated!
Hurly