-
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 its 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
-
Anyone? Getting desperate, please?
-
Just a tip on coding standards. You have way to much in your main method. Second please tell us what is your problem exactly.
-
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
-
Its going through your for loop twice.
-
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
-
Sounds possible just try. Programming is just like science 1% facts 99% experimenting.
-
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);
}
}
-
wow... That blows my idea out of the water.. perfect again!! Thanks so much.. Youve helped me out of a real thight spot there!!