Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





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.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-16-2007, 08:02 AM
Member
 
Join Date: Dec 2007
Posts: 13
coe11n is on a distinguished road
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
File Type: zip ics102_071_project.zip (10.0 KB, 6 views)

Last edited by coe11n : 12-16-2007 at 10:10 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-16-2007, 12:44 PM
Member
 
Join Date: Dec 2007
Posts: 13
coe11n is on a distinguished road
please help me
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-16-2007, 11:22 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-17-2007, 09:43 PM
Member
 
Join Date: Dec 2007
Posts: 13
coe11n is on a distinguished road
i can not understand


i want loing screan in JOptionPane.showInputDialog
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-17-2007, 09:47 PM
Member
 
Join Date: Dec 2007
Posts: 13
coe11n is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 12-18-2007, 09:03 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
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
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 12-18-2007, 03:31 PM
Member
 
Join Date: Dec 2007
Posts: 13
coe11n is on a distinguished road
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



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
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 12-19-2007, 04:57 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
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.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 12-20-2007, 03:45 PM
Member
 
Join Date: Dec 2007
Posts: 13
coe11n is on a distinguished road
it does not work
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 12-21-2007, 12:05 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
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
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 12-26-2007, 03:50 PM
Member
 
Join Date: Dec 2007
Posts: 13
coe11n is on a distinguished road
does not work
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 12-26-2007, 08:24 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
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.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 12-27-2007, 12:47 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
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.
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 01-02-2008, 11:35 AM
simi's Avatar
Member
 
Join Date: Dec 2007
Location: Singapore
Posts: 18
simi is on a distinguished road
Send a message via Yahoo to simi
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
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 01-02-2008, 11:41 PM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
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.
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 01-03-2008, 12:28 AM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 01-03-2008, 12:33 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
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"));
Bookmark Post in Technorati
Reply With Quote
  #18 (permalink)  
Old 01-03-2008, 01:06 AM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 11:28 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org