I am having a problem with my final assignment. Now it began with an apology from my prof on the said assignment because for the pass 9 weeks we have done projects that has focused on a small part like change colors, stream, inheritance, etc. Now the final is to place it all together, but we haven't done any examples based on anything remotely close on this and he apologized yet again.
So here is what he wanted:
Create a Java GUI business application. This program may be any business application of your choice. A few examples include order entry, inventory management, payroll processing, or work order management. The application needs to read and write to a sequential access file. You will need to incorporate graphics, events, exception handling, and inheritance.
So first I decided to make up an game magazine subscription program using an inheritance here's a snippit of the main base:
public abstract class GameMagazineSubscriber
{
protected String address;
protected double rate;
public GameMagazineSubscriber() throws Exception
{
setAddress();
setRate();
}
public boolean equals(GameMagazineSubscriber nps)
{
boolean result;
if (address.equals(nps.address))
result = true;
else
result = false;
return result;
}
public String getAddress()
{
return address;
}
public double getRate()
{
return rate;
}
public void setAddress() throws Exception
{
String inputString = new String();
char newChar;
System.out.print("Enter address of subscriber ");
newChar = (char)System.in.read();
while(newChar >='A' && newChar <='z'|| newChar == ' ' || (newChar>='0' && newChar <= '9'))
{
inputString = inputString + newChar;
newChar = (char)System.in.read();
}
System.in.read();
address = inputString;
}
public abstract void setRate();
}
The rest of the code has the inheritance asked for, but that is it so then I scratched it and decided to create a subscription mailing list like so:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class CreateMagazineMailList extends JFrame implements ActionListener
{
private JLabel headTitle = new JLabel("Mailing List");
private Font headFont = new Font("Courier", Font.ITALIC, 24);
private JLabel enterName = new JLabel("Enter subscriber magazine subcriber");
private JLabel name = new JLabel("Name");
private JTextField inputName = new JTextField(10);
private JLabel address = new JLabel("Address");
private JTextField inputAddress = new JTextField(20);
private JButton enterData = new JButton("Enter Data");
private Container con = getContentPane();
DataOutputStream outstream;
public CreateMagazineMailList()
{
super("Victor E. Campudoni-Final-Assignment-B");
try
{
outstream = new DataOutputStream(new FileOutputStream("MailList.dat"));
}
catch(IOException ex)
{
System.err.println("File not opened");
System.exit(1);
}
But again it is not what asked for. I e-mail my prof and his comment was "yes the assignment is a bit vauge and it asked to combine everything you learned this semester. However, we never covered how to write a complete program and thus lies the great wall. Just do the best that you can." Honestly?! this is my final here. So then I went and try to create a program based on plane reservation like so:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Plane extends JApplet
implements ActionListener {
JTextField input;
JLabel prompt1, prompt2;
JButton yesButton, noButton;
int section, seats[], smoking;
int nonsmoking, people;
public void init()
{
input = new JTextField( 4 );
input.addActionListener( this );
prompt1 = new JLabel( "Please type 1 for smoking" );
prompt2 = new JLabel( "Please type 2 for nonsmoking" );
yesButton = new JButton( "Yes" );
noButton = new JButton( "No" );
yesButton.addActionListener( this );
noButton.addActionListener( this );
yesButton.setEnabled( true );
noButton.setEnabled( true );
seats = new int[ 11 ];
smoking = 6;
nonsmoking = 1;
Container c = getContentPane();
c.setLayout( new FlowLayout() );
c.add( prompt1 );
c.add( prompt2 );
c.add( input );
c.add( yesButton );
c.add( noButton );
}
public void actionPerformed( ActionEvent e )
{
if ( e.getSource() == input && people <= 10 ) {
section = Integer.parseInt( input.getText() );
String s = "";
if ( section == 1 ) {
if ( smoking <= 10 && seats[ smoking ] == 0 ) {
s = "Smoking. Seat #" + smoking;
seats[ smoking++ ] = 1;
people++;
}
else if ( smoking > 10 && nonsmoking <= 5 ) {
// enable buttons
yesButton.setEnabled( true );
noButton.setEnabled( true );
s = "Smoking is full. Non-smoking?";
}
else
s = "Next flight leaves in 3 hours.";
}
else if ( section == 2 ) {
if ( seats[ nonsmoking ] == 0 && nonsmoking <= 5 ) {
s = "Nonsmoking. Seat #" + nonsmoking;
seats[ nonsmoking++ ] = 1;
people++;
}
else if ( nonsmoking > 5 && smoking <= 10 ) {
// enable buttons
yesButton.setEnabled( true );
noButton.setEnabled( true );
s = "Nonsmoking is full. Smoking?";
}
else
s = "Next flight leaves in 3 hours.";
}
else
s = "Invalid input.";
showStatus( s );
}
else if ( e.getSource() == yesButton ) {
if ( section == 1 ) {
showStatus( "Your seat assignment is " + nonsmoking );
seats[ nonsmoking++ ] = 1;
}
else { // section is 2
showStatus( "Your seat assignment is " + smoking );
seats[ smoking++ ] = 1;
}
++people;
noButton.setEnabled( true);
yesButton.setEnabled( true );
}
else if ( e.getSource() == noButton ) {
showStatus( "Next flight leaves in 3 hours." );
noButton.setEnabled( true );
yesButton.setEnabled( true );
}
}
}
Just as I thought I had it. It is just not working. I am in my wits ends and I need some guidance. Please help.