Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
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 05-04-2008, 08:26 PM
Member
 
Join Date: Nov 2007
Location: Dublin, Ireland
Posts: 12
Mark1989 is on a distinguished road
Send a message via MSN to Mark1989
Can anyone HELP PLEASE!!
Ok first of i wanna say I dont want people to do the program.. Just help out.. tips etc pls.. I need to learn too

so i have this project to do!!

Code:
Car hiring system Write a class for hire car details to display the following information: (i) Type of car: (ii) Year of car (iii) Registration number (iv) Number of days for hire (v) Cost of the car for the duration of hire. The cost of the car hire may be calculated based on a basic rate of €40 per day. The rate for cars older than 5 years is €30 per day. So for example if the duration of hire is for 5 days for a 2006 car, then the cost of the hire would be €200. If there are more than 6 days in duration for the hire period then a reduction of 9 % is given on the total cost of the car hire, regardless of it’s year. (A maximum 10 days car hire are allowed) The hire details will be obtained from the user and stored in a vector . You should also provide a means for savinbg the contents of this vector to a file and retrieving data from the file to the vector each time the program runs. Write a test program which will provide the following menu system: All prioe carr hire transactions should be loaded into the vector from the file once the program commences. A. Hire a car B. Delete a transaction C. Modify D. Display all E. Save F. Quit Option A: Prompts the user to enter the car hire details accordingly and store them in the vector. Option B: Prompts the user to enter the registration number of car and then display that transaction details as in the following example: Type : Nissan Micra Year : 2006 Registration : 06D 45678 No days hire : 4 Cost : 160.00 The user should then be asked if they wish to delete the transaction i.e. Delete Car Hire Transaction ‘Y’ / ‘N’ Only the characters ‘Y’ or ‘N’ should be accepted as inputs for this part of the Program. If the response is ‘Y’ the ticket should be deleted. If it is ‘N’, the program should return to the main menu. If any other input except ‘Y’ or’ N’ is entered at this point the user should be presented with an error message and the user asked to try again. Hint: Use a procedure called goAgain( ) to return a validated ‘Y’ / ‘N’ and use it throughout the assignment. Option C: Prompt the user to enter the registration number of car and then display that transaction detail. A message should ask the user if these are the correct details. A ‘Y’ answer should result in the user having to enter all details for that ticket once again. (‘Y’ and ‘N’ are the only possible entries for this part as in option B) Option D: Displays all car hire transactions on screen as in the following report: Nissan Micra : 2006 : 06D 46782 : 4 : € 160.00 Toyota Yaris : 2005 : 05D 23123 : 2 : € 80.00 Nissan Primera : 2007 : 07D 23123 : 3 : € 120.00 etc…. Press Return to Continue --------------------------------------------------------- Note : These details must remain on Screen until the user presses return. On depression of the Return Key, the user should return to the main menu. Option E: Open a text file and save the contents of the vector to this file. All menu options should be written in a separate procedure and functions passing any necessary information as parameters.
I know . . crazy eh!! thing is im totally screwed!! CTake a look at the code i have.. and even tell me whre to go next IM STUMPED


Code:
import java.util.*; class CarHire { public static void main(String[]args) { String make = new String(); // Public string String model = new String(); // public string String year = new String(); // Public String Vector v = new Vector(); // Create Vector 'v' for(int i =0; i<2; i++) // Inout the data for 3 Objects { Car c = new Car(); // Create a new Object each time around as 'c' using the Car class in a seperate file // Input Data System.out.print("Set Make: "); make = Keyboard.readString(); // 'make' declared above as a String c.setMake(make); // Pass 'make' to the "setMake" method in the Car class. System.out.print("Set Model: "); model = Keyboard.readString(); c.setModel(model); System.out.print("Set Year: "); year = Keyboard.readString(); c.setYear(year); v.add((Object) c); // Add Object to the Vector } displayVec(v); // Go to the DisplayVec Method below and pass Vector 'v' to it } // end Main // Displaying the Vector // static void displayVec(Vector data) // Vector 'v' is passed here as 'data' { for(int i=0; i<data.size(); i++){ // data.size is the size of the Vector Car c = new Car(); // Make new Object each time around c = (Car) data.elementAt(i); // Display the Car Object thats stored in the Vector at element/position (i) c.display(); // Display Method in the Car class file } } // end displayVec } // end class ExampleTest
__________________
Theres 10 types of people in this world, Those who understand binary and those who dont
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-05-2008, 12:43 AM
Member
 
Join Date: Nov 2007
Location: Dublin, Ireland
Posts: 12
Mark1989 is on a distinguished road
Send a message via MSN to Mark1989
Anyone? Getting desperate, please?
__________________
Theres 10 types of people in this world, Those who understand binary and those who dont
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-05-2008, 01:24 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
Just a tip on coding standards. You have way to much in your main method. Second please tell us what is your problem exactly.
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-05-2008, 01:34 AM
Member
 
Join Date: Nov 2007
Location: Dublin, Ireland
Posts: 12
Mark1989 is on a distinguished road
Send a message via MSN to Mark1989
OK main problem is, the user has to enter their car hire details.. which will then be installed in the vector. And will then print back to the screen.. its happening twice though.. instead of once? any ideas
__________________
Theres 10 types of people in this world, Those who understand binary and those who dont
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-05-2008, 02:06 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
Its going through your for loop twice.
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-05-2008, 02:12 AM
Member
 
Join Date: Nov 2007
Location: Dublin, Ireland
Posts: 12
Mark1989 is on a distinguished road
Send a message via MSN to Mark1989
OMG.. i totally over looked.. Sorry ha. Real noobish i am :| .. another thing.. wcould a switch statement be used at the start to prompt the user with, for example..

what would you like to do?

A. Hire a Car
B. Delete a transaction
C. Etc..

if so, is it possible to link the "case 1 etc" part of the switch, to different prcedures
__________________
Theres 10 types of people in this world, Those who understand binary and those who dont
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-05-2008, 02:18 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
Sounds possible just try. Programming is just like science 1% facts 99% experimenting.
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-05-2008, 02:24 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,144
hardwired is on a distinguished road
I see you've gotten some help underway. I made this up to help you get started.
Code:
import java.util.*; class CarHireTest { public static void main(String[] args) { Vector<CarHire> v = new Vector<CarHire>(); // I'll use a Scanner since I don't have // access to your Keyboard class. Scanner scanner = new Scanner(System.in); // Input the data for 3 Objects for(int i = 0; i < 2; i++) { // This section of code will be one option // on your menu of options. CarHire c = new CarHire(); // Input Data System.out.print("enter Make and model: "); String make = //Keyboard.readString(); scanner.nextLine(); c.setMake(make); System.out.print("enter Year: "); int year = //Keyboard.readString(); Integer.parseInt(scanner.nextLine()); c.setYear(year); System.out.print("enter registration: "); String reg = //Keyboard.readString(); scanner.nextLine(); c.setRegistration(reg); System.out.print("enter days: "); int days = //Keyboard.readString(); Integer.parseInt(scanner.nextLine()); c.setDuration(days); v.add(c); } // Go to the DisplayVec Method below and pass Vector 'v' to it displayVec(v); } // Displaying the Vector // static void displayVec(Vector data) { for(int i=0; i<data.size(); i++){ CarHire ch = (CarHire) data.elementAt(i); ch.display(); } } } // ExampleTest class CarHire { String makeAndModel; int year; String registration; int days; double costOfHire; public void setMake(String make) { makeAndModel = make; } public void setYear(int year) { this.year = year; } public void setRegistration(String r) { registration = r; } public void setDuration(int d) { days = d; } public double getCost() { // calculate cost here as described/required return 0.0; } public void display() { System.out.printf("%-15s: %s%n%-15s: %d%n%-15s: %s%n" + "%-15s: %d%n%-15s: %.2f%n%n", "Type", makeAndModel, "Year", year, "Registration", registration, "No days hire", days, "Cost", costOfHire); } }
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-05-2008, 02:38 AM
Member
 
Join Date: Nov 2007
Location: Dublin, Ireland
Posts: 12
Mark1989 is on a distinguished road
Send a message via MSN to Mark1989
wow... That blows my idea out of the water.. perfect again!! Thanks so much.. Youve helped me out of a real thight spot there!!
__________________
Theres 10 types of people in this world, Those who understand binary and those who dont
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 07:28 PM.


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