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
- import java.io.*;
- import java.util.Scanner;
- public class Vehicle2 {
- private static Scanner scan = new Scanner(System.in);
- public static void main(String[] args) {
- CarList theCarList = new CarList();
- char selection = 'x';
- while (selection != 'q')
- {
- clearScreen();
- System.out.println("\n ---------------------------------------------------------------------");
- System.out.println(" *** VEHICLE REGISTRY - MAIN MENU ***");
- System.out.println(" ---------------------------------------------------------------------\n");
- System.out.println();
- System.out.println(" Type : ");
- System.out.println(" a - To insert a new taxi into the vehicle registry");
- System.out.println(" d - To delete a taxi from the vehicle registry");
- System.out.println(" q - To quit the program\n");
- System.out.print(" Please make a selection: ");
- selection = scan.next().charAt(0);
- scan.nextLine();
- switch (selection) {
- case 'a': addATaxi(theCarList);
- break;
- }
- }
- private static void addATaxi(CarList theCarList) {
- String[][] taxiData = new String[5][5];
- double [][] taxiData2 = new double[5][2];
- double taxiPrice = 0.0;
- double taxiSpeed = 0.0;
- clearScreen();
- System.out.println("\n ---------------------------------------------------------------------");
- System.out.println(" *** VEHICLE REGISTRY - ADD A TAXI ***");
- System.out.println(" ---------------------------------------------------------------------\n");
- taxiData[0][0] = inputValidString("Vehicle Plate Number");
- taxiData[0][1] = inputValidString("Vehicle Brand Name");
- taxiData[0][2] = inputValidString("Vehicle Model");
- taxiData[0][3] = inputValidString("Taxi Registration Number");
- taxiData[0][4] = inputValidString("Taxi Company Name");
- try {
- System.out.println("Please Enter the vehicle price :");
- taxiData2[0][0] = scan.nextDouble();
- }
- catch (Exception e)
- {
- System.out.println("Invalid Value Entered ");
- System.out.println("No New Vehicle was Added");
- return;
- }
- try {
- System.out.println("Please Enter the vehicle speed :");
- taxiData2[0][1] = scan.nextDouble();
- }
- catch (Exception e)
- {
- System.out.println("Invalid Value Entered ");
- System.out.println("No New Vehicle was Added");
- return;
- }
- System.out.print("Number Plate\tBrand Name\tModel Type\tTaxi Reg. No.\tTaxi Company\n\tV. Price\tV. Speed");
- for(int i=0;i<1;i++) {
- for(int j=0;j<5;j++) {
- System.out.print(taxiData[i][j]+"\t\t");
- }
- for (k=0;k<1;k++) {
- System.out.print(taxiData2[i][k]+"\t\t");
- }
- //move to new line
- System.out.print("\n");
- }
- pressReturn();
- }
- public static boolean validateString(String token) {
- if(token.length()>0 && token.length() <=12)
- return true;
- else
- return false;
- }
- public static String inputString(String name) {
- while (true) {
- System.out.println("Enter the "+name);
- String store = scan.nextLine();
- if(validateString(store)) {
- return store;
- }
- System.out.println("Invalid or Long "+name+" choose a valid "+name);
- }
- }
- }