|
|
Welcome to the Java Forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:
- have access to post topics
- communicate privately with other members (PM)
- not see advertisements between posts
- have the possibility to earn one of our surprises if you are an active member
- access many other special features that will be introduced later.
Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact us.
|
|

12-16-2007, 08:02 AM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
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
Last edited by coe11n : 12-16-2007 at 10:10 AM.
|
|

12-16-2007, 12:44 PM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
please help me
|
|

12-16-2007, 11:22 PM
|
|
Senior Member
|
|
Join Date: Jul 2007
Posts: 1,222
|
|
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.
|
|

12-17-2007, 09:43 PM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
i can not understand
i want loing screan in JOptionPane.showInputDialog
|
|

12-17-2007, 09:47 PM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
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
|
|

12-18-2007, 09:03 AM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
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 
|
|

12-18-2007, 03:31 PM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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
|
|

12-19-2007, 04:57 AM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
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.
|
|

12-20-2007, 03:45 PM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
it does not work
|
|

12-21-2007, 12:05 PM
|
 |
Moderator
|
|
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
|
|
|
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
|
|

12-26-2007, 03:50 PM
|
|
Member
|
|
Join Date: Dec 2007
Posts: 13
|
|
|
does not work
|
|

12-26-2007, 08:24 PM
|
 |
Moderator
|
|
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
|
|
|
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.
|
|

12-27-2007, 12:47 AM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
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.
|
|

01-02-2008, 11:35 AM
|
 |
Member
|
|
Join Date: Dec 2007
Location: Singapore
Posts: 18
|
|
|
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
|
|

01-02-2008, 11:41 PM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
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.
|
|

01-03-2008, 12:28 AM
|
 |
Senior Member
|
|
Join Date: Dec 2007
Location: South Africa
Posts: 334
|
|
|
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. 
__________________
If your ship has not come in yet then build a lighthouse.
|
|

01-03-2008, 12:33 AM
|
 |
Senior Member
|
|
Join Date: Nov 2007
Location: New York
Posts: 143
|
|
|
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"));
|
|

01-03-2008, 01:06 AM
|
 |
Senior Member
|
|
Join Date: Dec 2007
Location: South Africa
Posts: 334
|
|
|
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.
__________________
If your ship has not come in yet then build a lighthouse.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|