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.

what errors are you getting?
also add comments at some point makes my job a lot easier and makes people like me want to help you

Edited 6 Years Ago by theABCasian: n/a

ok ive been tinkering with the code got it to run on my system by adding

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Plane extends JApplet
           implements ActionListener {
   /**
    * 
    */
private static final long serialVersionUID = 445324447064892368L;
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 );
.....

is it a logic error or are you stuck somewhere else?
in other words Ask Your Question Better :D

Edited 6 Years Ago by theABCasian: n/a

apologies, I was very angry when I posted the question. My problem with the plane code is when I compile and run it, it just gives me the smoking or non-smoking. When I enter a respond for either one and press the yes button,nothing happens. I would like to know what I have done wrong. Also I was wondering what can I do to incorporate the other items requested. You don't have to alter the code, but I would like some advise on how to do it. I posted the others because I was stuck on how to combine all of those together into one program. Again my apology.

When I enter a respond for either one and press the yes button,nothing happens.

Add some System.out.println(what is happening here) statements to the code to show what is happening at that point.

to anser what is happening with the smoking yes button a value is being added to your array and it is being overflowed when it hits 10 (your set limit) (look into arraylist) i would recommend taking a look at your console when running the program, toss in 15 or so smokers and take a look, it outputs an error if index out of bounds. hense array list above or the other option would be to set a limiter and tell it to post full or somthing.
as for your other code integrating it would require either making a larger gui or a main menu gui i would recommend looking into a gui editor as it makes java gui life a lot easier its like using paint to build a window as opposed to say the oral surgery that is writing java gui code

<update>
ok after looking over your other code i would put you at about 40% or so done i might recommend if you have time looking into building something a little more organized dropp all start over find a gui editor and build your gui if gui is required and then build a single program that fits your requirements best bet is a inventory management system as they are easy to write and you can use classing as you mentioned you needed.
as for not knowing how to tie in a bunch of classes this may help use your imports

#import "foo.java"
#import "bar.java"

allows you to use java properly by creating objects of foo and bar respectively
if you build a inventory management system for dogs the sudo code would go...

main.java
import dog, bigdog, sickbigdog, smalldog
dog1 = new dog
dog2 = new big dog
dog3 = new sick big dog
dog4 = new small dog
or use arrays/arraylists of dogs
output choose dog to modify
call doggs modify method
gui
ect...

dog.java
dog variables, name
dog method, bark

bigdog.java
import dog.java
big dog extends dog
bigdog variables, size
any needed methods

sickbigdog.java
import bigdog.java
sickbigdog extends big dog
sickbigdof variables, healthstatus
any needed methods

smalldog.java
import dog.java
smalldog extends dog
small dog variables...
small dog methods...

that is how classing works using the extends to link similar items and you imports to make instances of these items

Edited 6 Years Ago by theABCasian: update

Thank you for your response I will give this a go and give you an update. Again thank you.

This article has been dead for over six months. Start a new discussion instead.