Results 1 to 18 of 18
  1. #1
    coe11n is offline Member
    Join Date
    Dec 2007
    Posts
    13
    Rep Power
    0

    Default please i need help

    hi




    I am a new one here and in java



    could any body help me please



    i hava a project in java and the half of th matterial i did not take it yet



    the project from introduction to java until arrays



    this is the project



    Introduction
    The idea of the project is to make an Airline Reservation System. The system should have four classes (Flight, Passenger, Reservation and AirlineSystem). The system should allow Airline agent to store and retrieve the information of a Flight and passengers reservations. The system should have to mode: Administrative mode and normal mode depending on the user account.( you have to have account.txt that store the username,password,mode).
    The features provided by the system are:
    • Welcome Screen and Login Screen.
    o Take the username and the password from the user using JOptionPane.showInputDialog method.
    o You have to check for a correct username and password.
    o You have to print appropriate welcome message using showMessageDialog then print the application menu in a console screen if the user and password are correct, kick the user out otherwise if he unable to enter the correct password in three trials.
    • Print the Reservation Menu as follows if the user is Administrator:
    o 1- Create a new Flight. – in this step you will create a new Flight object and store it in Flight.txt file.
    o 2- Create a new Reservation. – in this step you will create a passenger object and a reservation object and store it in a Files passenger.txt and reservation.txt.
    o 3- Modify passenger information.
    o 4- Modify Flight information.
    o 5- Cancel reservation. – in this step you will make sure you update the Flight object and corresponding files (Flight.txt , passenger.txt, reservation.txt).
    o 6- Display reservation information.
    o 7- Display Flight information.
    o 8- Display all reservation in a Flight.
    • Allow the normal passenger to login and
    o View all his reservation
    o Cancel one of his reservation
    o Create a new reservation, in this step you will do the following:
     Print the available flights
     Ask the user to enter flight number
     Display the seats available in that flight
     Prompt for seat desired, the user can type in a seat.
     You should then make the reservation object and make the update to Flight object and save
    o Modify his information



    and the Design see the Attachment
    Attached Files Attached Files
    Last edited by coe11n; 12-16-2007 at 08:10 AM.

  2. #2
    coe11n is offline Member
    Join Date
    Dec 2007
    Posts
    13
    Rep Power
    0

    Default

    please help me

  3. #3
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    The introduction and the Word document pretty well lay this out for you. The Word doc even describes the classes and their fields and methods for you. I would start at the top of the introduction with the first line: welcome and login screens. You can get some ideas for components to use from here Lesson: Using Swing Components.

  4. #4
    coe11n is offline Member
    Join Date
    Dec 2007
    Posts
    13
    Rep Power
    0

    Default

    i can not understand


    i want loing screan in JOptionPane.showInputDialog

  5. #5
    coe11n is offline Member
    Join Date
    Dec 2007
    Posts
    13
    Rep Power
    0

    Default

    import javax.swing.*;
    public class JOptionPaneTest {

    public static void main(String[] args){

    String name = JOptionPane.showInputDialog("Please Enter Your name");

    JOptionPane.showMessageDialog(null,"Welcome "+name);

    }
    }






    this is a welcom screan



    i want a loing screan (user name and password) save it in file.txt




    thanks

  6. #6
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    Ok in order to have it save information to a file, you can use PrintWriter of the java.io package. Now, i know what you're going to see will be a bit advanced (due to the use of Exception handling), but i'll explain everything after I show you the code I've constructed.
    ------------------------------------------------

    import java.io.PrintWriter;
    import java.io.IOException;
    import javax.swing.*;
    public class JOptionPaneTest
    {

    public static void main(String[] args)
    {
    String name = JOptionPane.showInputDialog("Please Enter Your name");

    JOptionPane.showMessageDialog(null,"Welcome " + name);
    String password = JOptionPane.showInputDialog("Please Enter Your Password");



    try
    {
    PrintWriter out = new PrintWriter("file.txt");
    out.println(name);
    out.println(password);
    out.close();

    }
    catch(IOException e)
    {
    System.out.println("Error processing file: " + e);
    }


    }
    }

    --------------------------

    After you run this program, a new file (file.txt) will be created in whatever folder your program is in.

    Now, let me explain why I have try and catch. If you were to not have these you would get a compile-time error because whenever you are dealing with files there is always the possibility of the file not being found, or that the file is corrupted. As a result, we must handle the exception, if it is thrown. So, we say try { code here} and catch (Exception name). It "tries" to see if the code will work, and if there is an exception, the catch statement "catches" it. So, in this code, it tries to write the file, but if there is an IOException, it catches it, and displays "Error processing file" + the details of the exception. (By the way, IOException is a type of exception that deals with Input and Output). So yeah, I know it might be a little hard to understand at first, but if you need me to explain it better just ask.

    So, as you will see, everything works fine. Now, your next step is to make it so that it reads the file. For this, you use the FileReader class. So, you make a new FileReader and then a new Scanner, and you pass your FileReader object through the parameters of the Scanner. Try to see if you can figure this out on your own. If not, just ask and I'll be happy to help you out.

    Good luck :D

  7. #7
    coe11n is offline Member
    Join Date
    Dec 2007
    Posts
    13
    Rep Power
    0

    Default

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



    hi


    your program when i run it


    C:\Documents and Settings\Administrator\Desktop\JOptionPaneTest.jav a:18: cannot resolve symbol
    symbol : constructor PrintWriter (java.lang.String)
    location: class java.io.PrintWriter
    PrintWriter out = new PrintWriter("file.txt");
    ^
    1 error

    Process completed.





    please what is the problem





    thanks

  8. #8
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    hm, i copied and pasted my code, and its working fine for me. the only thing i can think of, is that you didnt import java.io.PrintWriter;

    So i mean, i dont know man, it should be working fine. If it still isnt working, do you think you could copy and paste it here, so i can see what the problem is.

  9. #9
    coe11n is offline Member
    Join Date
    Dec 2007
    Posts
    13
    Rep Power
    0

    Default

    it does not work

  10. #10
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    You may want to check on which version of Java you're using. Gibson's code works for me too, so coe11n - cut an paste your *exact* code, and please use the code tags feature when posting.

    -Capt

  11. #11
    coe11n is offline Member
    Join Date
    Dec 2007
    Posts
    13
    Rep Power
    0

    Default

    does not work

  12. #12
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    If repeating your post is your idea of making progress, then you're going to be here for a very long time. Best of luck to you.

  13. #13
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    yea i agree with CaptainMorgan, you can't just say "it doesn't work" and give up, and expect everyone to just give you the source code you know, like, i'm willing to help, but the thing about programming is that you have to figure out stuff on your own. the code i made does work. it even worked for CaptainMorgan , so we know that i'm not making it up. So yeah, when you told me what your problem is, i recognized it to either be an issue that you didn't import PrintWriter, or that the PrintWriter class does not have a constructor that calls a String for its parameters, but, i know for a fact that it does have said constructor. So yea man, keep trying to figure it out, it's a very important thing for a programmer to be able to resolve compile-time, run-time and logic errors.

  14. #14
    simi's Avatar
    simi is offline Member
    Join Date
    Dec 2007
    Location
    Singapore
    Posts
    18
    Rep Power
    0

    Default

    Hi,

    import java.io.PrintWriter;
    import java.io.IOException;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import javax.swing.*;
    public class Test
    {

    public static void main(String[] args)
    {
    String name = JOptionPane.showInputDialog("Please Enter Your name");

    JOptionPane.showMessageDialog(null,"Welcome " + name);
    String password = JOptionPane.showInputDialog("Please Enter Your Password");



    try
    {
    BufferedWriter bufferedwriter = new BufferedWriter(
    new FileWriter("C:\\Test\\file.txt"));

    PrintWriter out = new PrintWriter(bufferedwriter);
    out.println(name);
    out.println(password);
    out.close();

    }
    catch(IOException e)
    {
    System.out.println("Error processing file: " + e);
    }


    }
    }


    updated Gibson's code. The above code will create file.txt in c:\test directory. before running this code , dont forget to create test directory.

    This reservation project is a good start to learn java. i've learned java 8 years back by doing these kind of projects instead of reading more theory. i would like to suggest you to start it and when you encounter error post it here. we will try our best to help.

    All the best.

    Simi

    Regards,
    Simi

  15. #15
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    ah, simi, i've never used BufferedWriter. I've checked out the API and it doesn't seem much different than PrintWriter. So why exactly do you use BufferedWriter (or BufferedReader, for that matter). Thanks for any help.

  16. #16
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Default Buffers

    Hello, gibsonrocker800.

    Look at this example:
    If you are asked to read a book and someone only gives you one page at a time to read then it will take a while to do so. (no buffer) If you are given the book (buffer), then you can read at your own pace, and you do not have to wait for the pages to arrive. (lets say from your your hard drive) So, the BufferedWriter is used to increase speed.

    Hope this helps.;)
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

  17. #17
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    ah ok, thanks alot for the help. but do you always have to pass a new FileWriter through a new BufferedWriter, as simi did:

    BufferedWriter bufferedwriter = new BufferedWriter(
    new FileWriter("C:\\Test\\file.txt"));

  18. #18
    tim's Avatar
    tim
    tim is offline Senior Member
    Join Date
    Dec 2007
    Posts
    435
    Rep Power
    7

    Red face

    I'm not sure, but I know that if you add a buffer onto a buffer accidentally, you can lose a lot of processing time. Maybe Captain Morgan knows.
    Eyes dwelling into the past are blind to what lies in the future. Step carefully.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •