473,769 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Vehicle-Taxi Program

7 New Member
Hi guys, at the moment, im rushing to get my assignment done as the dateline is soon. Haven't had much time lately, so i'm in need of some help.

Im supposed to create a program that :
Has a Vehicle superclass, and a Taxi subclass.

1) Can accept new Taxi into an array
2) Can delete old records of Taxi from the array
3) Have to be able to retain the previous added data (which i think most likely im gonna do it by saving and reading the data from the array into a txt file of which im still wondering how)
4) Able to sort the records
5) Able to show the average price.

What i've done so far is this :
Just to test out if my 2dimensional array is working fine, but apparently i get an error when i compile.

Any help is appreciated.

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.util.Scanner;
  3.  
  4. public class Vehicle2 {
  5.     private static Scanner scan = new Scanner(System.in);
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         CarList theCarList = new CarList();
  10.         char selection = 'x';
  11.         while (selection != 'q') 
  12.         {
  13.         clearScreen();
  14.          System.out.println("\n  ---------------------------------------------------------------------");
  15.          System.out.println("                ***     VEHICLE REGISTRY - MAIN MENU     ***");
  16.          System.out.println("  ---------------------------------------------------------------------\n");
  17.          System.out.println();
  18.          System.out.println("  Type : ");
  19.          System.out.println("    a  -  To insert a new taxi into the vehicle registry");
  20.          System.out.println("    d  -  To delete a taxi from the vehicle registry");
  21.          System.out.println("    q  -  To quit the program\n");
  22.          System.out.print(" Please make a selection: ");
  23.          selection = scan.next().charAt(0);
  24.          scan.nextLine();
  25.  
  26.          switch (selection) {
  27.          case 'a': addATaxi(theCarList);
  28.                 break;
  29.          }
  30.         }
  31.  
  32.         private static void addATaxi(CarList theCarList) {
  33.             String[][] taxiData = new String[5][5];
  34.             double [][] taxiData2 = new double[5][2];
  35.  
  36.             double taxiPrice = 0.0;
  37.             double taxiSpeed = 0.0;
  38.             clearScreen();
  39.             System.out.println("\n ---------------------------------------------------------------------");
  40.             System.out.println("                 ***    VEHICLE REGISTRY - ADD A TAXI     ***");
  41.             System.out.println("  ---------------------------------------------------------------------\n");
  42.  
  43.             taxiData[0][0] = inputValidString("Vehicle Plate Number");
  44.             taxiData[0][1] = inputValidString("Vehicle Brand Name");
  45.             taxiData[0][2] = inputValidString("Vehicle Model");
  46.             taxiData[0][3] = inputValidString("Taxi Registration Number");
  47.             taxiData[0][4] = inputValidString("Taxi Company Name");
  48.  
  49.             try {
  50.                 System.out.println("Please Enter the vehicle price :");
  51.                 taxiData2[0][0] = scan.nextDouble();
  52.             }
  53.             catch (Exception e)
  54.             {
  55.             System.out.println("Invalid Value Entered ");
  56.             System.out.println("No New Vehicle was Added");
  57.             return;
  58.             }
  59.  
  60.             try {
  61.                 System.out.println("Please Enter the vehicle speed :");
  62.                 taxiData2[0][1] = scan.nextDouble();
  63.             }
  64.             catch (Exception e)
  65.             {
  66.             System.out.println("Invalid Value Entered ");
  67.             System.out.println("No New Vehicle was Added");
  68.             return;
  69.             }
  70.  
  71.             System.out.print("Number Plate\tBrand Name\tModel Type\tTaxi Reg. No.\tTaxi Company\n\tV. Price\tV. Speed");
  72.             for(int i=0;i<1;i++) {
  73.                 for(int j=0;j<5;j++) {
  74.                     System.out.print(taxiData[i][j]+"\t\t");
  75.                 }
  76.                 for (k=0;k<1;k++) {
  77.                     System.out.print(taxiData2[i][k]+"\t\t");
  78.                 }
  79.                //move to new line
  80.                System.out.print("\n");
  81.             }
  82.             pressReturn();
  83.         }
  84.  
  85.         public static boolean validateString(String token) {
  86.             if(token.length()>0 && token.length() <=12)
  87.                 return true;
  88.             else 
  89.                 return false;
  90.         }
  91.  
  92.         public  static String inputString(String name) {
  93.             while (true) {
  94.                 System.out.println("Enter the "+name);
  95.                 String store = scan.nextLine();
  96.                 if(validateString(store)) {
  97.                     return store;
  98.                 }
  99.                 System.out.println("Invalid or Long "+name+"  choose a valid "+name);
  100.             }
  101.         }
  102. }
  103.  
Feb 27 '07 #1
6 3514
r035198x
13,262 MVP
Hi guys, at the moment, im rushing to get my assignment done as the dateline is soon. Haven't had much time lately, so i'm in need of some help.

Im supposed to create a program that :
Has a Vehicle superclass, and a Taxi subclass.

1) Can accept new Taxi into an array
2) Can delete old records of Taxi from the array
3) Have to be able to retain the previous added data (which i think most likely im gonna do it by saving and reading the data from the array into a txt file of which im still wondering how)
4) Able to sort the records
5) Able to show the average price.

What i've done so far is this :
Just to test out if my 2dimensional array is working fine, but apparently i get an error when i compile.

Any help is appreciated.

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import java.util.Scanner;
  3.  
  4. public class Vehicle2 {
  5.     private static Scanner scan = new Scanner(System.in);
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         CarList theCarList = new CarList();
  10.         char selection = 'x';
  11.         while (selection != 'q') 
  12.         {
  13.         clearScreen();
  14. System.out.println("\n ---------------------------------------------------------------------");
  15. System.out.println(" *** VEHICLE REGISTRY - MAIN MENU ***");
  16. System.out.println(" ---------------------------------------------------------------------\n");
  17. System.out.println();
  18.          System.out.println(" Type : ");
  19.          System.out.println(" a - To insert a new taxi into the vehicle registry");
  20.          System.out.println(" d - To delete a taxi from the vehicle registry");
  21.          System.out.println(" q - To quit the program\n");
  22.          System.out.print(" Please make a selection: ");
  23.          selection = scan.next().charAt(0);
  24.          scan.nextLine();
  25.  
  26.          switch (selection) {
  27.          case 'a': addATaxi(theCarList);
  28.                 break;
  29.          }
  30.         }
  31.  
  32.         private static void addATaxi(CarList theCarList) {
  33.             String[][] taxiData = new String[5][5];
  34.             double [][] taxiData2 = new double[5][2];
  35.  
  36.             double taxiPrice = 0.0;
  37.             double taxiSpeed = 0.0;
  38.             clearScreen();
  39.             System.out.println("\n ---------------------------------------------------------------------");
  40.             System.out.println(" *** VEHICLE REGISTRY - ADD A TAXI ***");
  41.             System.out.println(" ---------------------------------------------------------------------\n");
  42.  
  43.             taxiData[0][0] = inputValidString("Vehicle Plate Number");
  44.             taxiData[0][1] = inputValidString("Vehicle Brand Name");
  45.             taxiData[0][2] = inputValidString("Vehicle Model");
  46.             taxiData[0][3] = inputValidString("Taxi Registration Number");
  47.             taxiData[0][4] = inputValidString("Taxi Company Name");
  48.  
  49.             try {
  50.                 System.out.println("Please Enter the vehicle price :");
  51.                 taxiData2[0][0] = scan.nextDouble();
  52.             }
  53.             catch (Exception e)
  54.             {
  55.             System.out.println("Invalid Value Entered ");
  56.             System.out.println("No New Vehicle was Added");
  57.             return;
  58.             }
  59.  
  60.             try {
  61.                 System.out.println("Please Enter the vehicle speed :");
  62.                 taxiData2[0][1] = scan.nextDouble();
  63.             }
  64.             catch (Exception e)
  65.             {
  66.             System.out.println("Invalid Value Entered ");
  67.             System.out.println("No New Vehicle was Added");
  68.             return;
  69.             }
  70.  
  71.             System.out.print("Number Plate\tBrand Name\tModel Type\tTaxi Reg. No.\tTaxi Company\n\tV. Price\tV. Speed");
  72.             for(int i=0;i<1;i++) {
  73.                 for(int j=0;j<5;j++) {
  74.                     System.out.print(taxiData[i][j]+"\t\t");
  75.                 }
  76.                 for (k=0;k<1;k++) {
  77.                     System.out.print(taxiData2[i][k]+"\t\t");
  78.                 }
  79.              //move to new line
  80.              System.out.print("\n");
  81.             }
  82.             pressReturn();
  83.         }
  84.  
  85.         public static boolean validateString(String token) {
  86.             if(token.length()>0 && token.length() <=12)
  87.                 return true;
  88.             else 
  89.                 return false;
  90.         }
  91.  
  92.         public static String inputString(String name) {
  93.             while (true) {
  94.                 System.out.println("Enter the "+name);
  95.                 String store = scan.nextLine();
  96.                 if(validateString(store)) {
  97.                     return store;
  98.                 }
  99.                 System.out.println("Invalid or Long "+name+" choose a valid "+name);
  100.             }
  101.         }
  102. }
  103.  
1.)You did not specify that error that you got.
2.)You don't have to post all your code for this. Just the bits where you need specific help with.
3.)Did you write the Vehicle and Taxi classes correctly(You don't have to post them)?
Feb 27 '07 #2
xdeath
7 New Member
1.)You did not specify that error that you got.
2.)You don't have to post all your code for this. Just the bits where you need specific help with.
3.)Did you write the Vehicle and Taxi classes correctly(You don't have to post them)?
Error that i got is : Vehicle2.java:3 2: illegal start of expression
private static void addATaxi(CarLis t theCarList) {
^
1 error.

Uh, in this one, i dont think vehicle and taxi classes are even used yet? im just testing out if the main menu + receive input for the addTaxi method is working properly...
Feb 27 '07 #3
r035198x
13,262 MVP
Error that i got is : Vehicle2.java:3 2: illegal start of expression
private static void addATaxi(CarLis t theCarList) {
^
1 error.

Uh, in this one, i dont think vehicle and taxi classes are even used yet? im just testing out if the main menu + receive input for the addTaxi method is working properly...
You cannot test anything before you write the Vehicle and Taxi classes. Write those first. You will need to be creating instances of Taxis in the test class and you cannot do that before you write the Taxi class.
Feb 27 '07 #4
xdeath
7 New Member
You cannot test anything before you write the Vehicle and Taxi classes. Write those first. You will need to be creating instances of Taxis in the test class and you cannot do that before you write the Taxi class.
hmm okay... uh im not very good at java so yea, correct me if anything's amiss..

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class Vehicle {
  3.     private String plateNum;
  4.     private String brandName;
  5.     private String modelType;
  6.     private double vehicleSpeed;
  7.     private double vehiclePrice;
  8.  
  9.     public void setPlateNum(String plateNum) {
  10.         this.plateNum = plateNum;
  11.     }
  12.  
  13.     public void setBrandName(String brandName) {
  14.         this.brandName = brandName;
  15.     }
  16.  
  17.     public void setModelType(String modelType) {
  18.         this.modelType = modelType;
  19.     }
  20.  
  21.     public void setVehicleSpeed(double vehicleSpeed) {
  22.         this.vehicleSpeed = vehicleSpeed;
  23.     }
  24.  
  25.     public void setVehiclePrice(double vehiclePrice) {
  26.         vehiclePrice = vehiclePrice;
  27.     }
  28.  
  29.     public String getPlateNum() {
  30.         return this.plateNum;
  31.     }
  32.  
  33.     public String getBrandName() {
  34.         return this.brandName;
  35.     }
  36.  
  37.     public String getModelType() {
  38.         return this.modelType;
  39.     }
  40.  
  41.     public double getVehicleSpeed() {
  42.         return this.vehicleSpeed;
  43.     }
  44.  
  45.     public double getVehiclePrice() {
  46.         return this.vehiclePrice;
  47.     }
  48. }
  49.  
  50.  
  51. public class Taxi extends Vehicle {
  52.     private String tRegNum;
  53.     private String tCompany;
  54.  
  55.     public void setTRegNum(String tRegNum) {
  56.         this.tRegNum = tRegNum;
  57.     }
  58.  
  59.     public void setTCompany(String tCompany) {
  60.         this.tCompany = tCompany;
  61.     }
  62.  
  63.     public String getTRegNum() {
  64.         return this.tRegNum;
  65.     }
  66.  
  67.     public String getTCompany() {
  68.         return this.tCompany;
  69.     }
  70. }
  71.  
Feb 27 '07 #5
sicarie
4,677 Recognized Expert Moderator Specialist
hmm okay... uh im not very good at java so yea, correct me if anything's amiss..

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class Vehicle {
  3.     private String plateNum;
  4.     private String brandName;
  5.     private String modelType;
  6.     private double vehicleSpeed;
  7.     private double vehiclePrice;
  8.  
  9.     public void setPlateNum(String plateNum) {
  10.         this.plateNum = plateNum;
  11.     }
  12.  
  13.     public void setBrandName(String brandName) {
  14.         this.brandName = brandName;
  15.     }
  16.  
  17.     public void setModelType(String modelType) {
  18.         this.modelType = modelType;
  19.     }
  20.  
  21.     public void setVehicleSpeed(double vehicleSpeed) {
  22.         this.vehicleSpeed = vehicleSpeed;
  23.     }
  24.  
  25.     public void setVehiclePrice(double vehiclePrice) {
  26.         vehiclePrice = vehiclePrice;
  27.     }
  28.  
  29.     public String getPlateNum() {
  30.         return this.plateNum;
  31.     }
  32.  
  33.     public String getBrandName() {
  34.         return this.brandName;
  35.     }
  36.  
  37.     public String getModelType() {
  38.         return this.modelType;
  39.     }
  40.  
  41.     public double getVehicleSpeed() {
  42.         return this.vehicleSpeed;
  43.     }
  44.  
  45.     public double getVehiclePrice() {
  46.         return this.vehiclePrice;
  47.     }
  48. }
  49.  
  50.  
  51. public class Taxi extends Vehicle {
  52.     private String tRegNum;
  53.     private String tCompany;
  54.  
  55.     public void setTRegNum(String tRegNum) {
  56.         this.tRegNum = tRegNum;
  57.     }
  58.  
  59.     public void setTCompany(String tCompany) {
  60.         this.tCompany = tCompany;
  61.     }
  62.  
  63.     public String getTRegNum() {
  64.         return this.tRegNum;
  65.     }
  66.  
  67.     public String getTCompany() {
  68.         return this.tCompany;
  69.     }
  70. }
  71.  
Other than a constructor by which to instantiate (create) your objects, I think you're on the right track.
Feb 27 '07 #6
r035198x
13,262 MVP
hmm okay... uh im not very good at java so yea, correct me if anything's amiss..

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class Vehicle {
  3.     private String plateNum;
  4.     private String brandName;
  5.     private String modelType;
  6.     private double vehicleSpeed;
  7.     private double vehiclePrice;
  8.  
  9.     public void setPlateNum(String plateNum) {
  10.         this.plateNum = plateNum;
  11.     }
  12.  
  13.     public void setBrandName(String brandName) {
  14.         this.brandName = brandName;
  15.     }
  16.  
  17.     public void setModelType(String modelType) {
  18.         this.modelType = modelType;
  19.     }
  20.  
  21.     public void setVehicleSpeed(double vehicleSpeed) {
  22.         this.vehicleSpeed = vehicleSpeed;
  23.     }
  24.  
  25.     public void setVehiclePrice(double vehiclePrice) {
  26.         vehiclePrice = vehiclePrice;
  27.     }
  28.  
  29.     public String getPlateNum() {
  30.         return this.plateNum;
  31.     }
  32.  
  33.     public String getBrandName() {
  34.         return this.brandName;
  35.     }
  36.  
  37.     public String getModelType() {
  38.         return this.modelType;
  39.     }
  40.  
  41.     public double getVehicleSpeed() {
  42.         return this.vehicleSpeed;
  43.     }
  44.  
  45.     public double getVehiclePrice() {
  46.         return this.vehiclePrice;
  47.     }
  48. }
  49.  
  50.  
  51. public class Taxi extends Vehicle {
  52.     private String tRegNum;
  53.     private String tCompany;
  54.  
  55.     public void setTRegNum(String tRegNum) {
  56.         this.tRegNum = tRegNum;
  57.     }
  58.  
  59.     public void setTCompany(String tCompany) {
  60.         this.tCompany = tCompany;
  61.     }
  62.  
  63.     public String getTRegNum() {
  64.         return this.tRegNum;
  65.     }
  66.  
  67.     public String getTCompany() {
  68.         return this.tCompany;
  69.     }
  70. }
  71.  
1.)You don't have to post all your code.
2.)You need to put at least two constructors for each of these classes for creating the objects with. One should be the default (no-arg cnstructor and one should take the required arguments necessary to create meaningful objects with these classes)
3.)You need to be able to compare these objects with each other so you need to implement the Comparable interface and add the compareTo method.
Feb 27 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
6342
by: noname | last post by:
Hello all, I use Access to keep track of approx. 80 vehicles. I have a table of vehicles with specs. I have another of service records linked to the vehicle table. Works great! I can expand each vehicle to see what service I have performed on just that vehicle. I also have tables for billing categories, employees and departments. So far so good. Now I need to make it to where I can enter the fuel used by each vehicle when someone fills...
1
4827
by: Johann Blake | last post by:
You can read an article on a novel approach on how to build an inexpensive system to track a vehicle or any other type of object using a GPS receiver and other off-the-shelf hardware like a GSM/GPRS modem. The article is found at: http://www.closerworlds.com/eng/Resources/GPS_Vehicle_Tracking.html This is part I in a series. By CloserWorlds
6
5297
by: jimfortune | last post by:
In: http://groups.google.com/group/comp.databases.ms-access/msg/60d7faa790c65db1 james.ea...@gmail.com said: :Ok, I've answered the first half of my own question. From a MSDN :article, I can now use the following to reference the last primary :key's values: :
2
969
by: Jesse Johnson | last post by:
I dont know if this question belongs in here, but I will try. Does anyone know where I could get a veicle sales DB??? Example: someone comes to the web app and they see "select make" then "selct model" then "select year" and finally "select options". Does anyone know if there is a datasource out there for this info? Thanks in advance. -- Jesse Johnson
35
1933
by: javelin | last post by:
I posted an answer to someone's question, and realized I have more questions than answers. Thus, I am going to post my scenario to get to the question that I have: I have a challenge, to figure out what part of the vehicle to relate parts to. I can't relate a part to the entire vehicle. Why? Well, a vehicle can have, apparently, more than one engine configuration. For example, I have a Honda Civic with a 1.5L engine, and it can come with...
2
1153
by: MLH | last post by:
Suppose you have tblVehicleJobs with keyfield. And say there's another table used to keep records of inbound letters you receive on each car. That table is named tblinLttrs and has as it's keyfield and has field which is used to link it to tblVehicleJobs. Since many letters (of several categories) could be sent in over time pertaining to a given vehicle, there is a hard-coded One To Many relationship from tblVehicleJobs to tblinLttrs...
0
1266
by: vince | last post by:
Until December, 31st, 2008 companies may obtain a free Developer License of the JOpt.NET Vehicle Routing Library The Vehicle Routing Initiative aims on software vendors that plan to incorporate advanced route planning and optimization features into their existing software product. Be it in Logistics, Field Service or Sales Force Planning ISVs are encouraged to contact DNA at http://www.dna-evolutions.com/vrinitiative.html
0
1180
by: vince | last post by:
Until December, 31st, 2008 companies may obtain a free Developer License of the JOpt.SDK Vehicle Routing Library The Vehicle Routing Initiative aims on software vendors that plan to incorporate advanced route planning and optimization features into their existing software product. Be it in Logistics, Field Service or Sales Force Planning ISVs are encouraged to contact DNA here to obtain a free Developer Express License including email...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9987
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8867
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7404
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5294
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.