473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Vehicle-Taxi Program

7
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 3478
r035198x
13,262 8TB
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
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:32: illegal start of expression
private static void addATaxi(CarList 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 8TB
Error that i got is : Vehicle2.java:32: illegal start of expression
private static void addATaxi(CarList 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
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 Expert Mod 4TB
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 8TB
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
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...
1
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...
6
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...
2
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...
35
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...
2
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...
0
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.