473,387 Members | 1,569 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,387 software developers and data experts.

Taxi program

Dear All,
I am a beginner in Java and would need your assistance with this assignment.
I have started PART A but I am not sure about how to proceed with PART B as we've not been taught and I dont know it either.

Submission is on Friday 2nd February 2007.

I await your responses

Rgds
Gonzzy

PART A
1) Write Java codes for a class vehicle with the given set of attributes (plate number,brand name, price and speed).
2) Create Java coded for a subclass Taxi with the attributes above.
3) Include objects instances for Taxis

PART B
1) Write Java codes to create an array of Taxi and instances of Taxi objects. Include the following specifications:

a) The program can display the average taxi price
b) The program can store new Taxis inside the array
c) The program can search for particular Taxi information
d) Any two features/attributes other than those stated in part A and B

Explaination that could aid better understanding is highly welcomed.
Jan 31 '07 #1
22 8677
horace1
1,510 Expert 1GB
once you haave implemented class Taxi and tested it you can create an array of them so
Expand|Select|Wrap|Line Numbers
  1.    Taxi taxis[]=new Taxi[20];        // create the array
  2.    for (int i=0;i<taxis.length;i++)
  3.       taxis[i]=new Taxi(.....);      // populate it wil Taxi objects
  4.  
Jan 31 '07 #2
Thanks Horace!
Sorry I forgot to state the extent I was able to go in PART A here it is

Expand|Select|Wrap|Line Numbers
  1. class vehicle
  2.         {
  3.         static String plateNumber;
  4.         String brandName;
  5.         int price;
  6.         int speed;    
  7.         }
  8.  
  9. class taxi extends vehicle
  10. {
  11. public static void  main(String d[])
  12. {
  13.  
Please assist on how to complete PART A and proceed with PART B
Many thanks
Jan 31 '07 #3
r035198x
13,262 8TB
Thanks Horace!
Sorry I forgot to state the extent I was able to go in PART A here it is

Expand|Select|Wrap|Line Numbers
  1. class vehicle
  2.         {
  3.         static String plateNumber;
  4.         String brandName;
  5.         int price;
  6.         int speed;    
  7.         }
  8.  
  9. class taxi extends vehicle
  10. {
  11. public static void main(String d[])
  12. {
  13.  
Please assist on how to complete PART A and proceed with PART B
Many thanks
price must be double not int maybe(speed too).
You should start class name with capital letters
Plate number should not be static (it is different for each vehicle) Read the Java classes on this site to see where the static word is used.
Yor vehicle class needs more flesh. You should make the attributes of the vehicle class private and provide getter and setter methods for them. You also need to put at least two constructors for that class. Make these changes and post here.
Feb 1 '07 #4
price must be double not int maybe(speed too).
You should start class name with capital letters
Plate number should not be static (it is different for each vehicle) Read the Java classes on this site to see where the static word is used.
Yor vehicle class needs more flesh. You should make the attributes of the vehicle class private and provide getter and setter methods for them. You also need to put at least two constructors for that class. Make these changes and post here.
I have done the part A but needs the solution to part B.
please assist
Feb 28 '07 #5
once you haave implemented class Taxi and tested it you can create an array of them so
Expand|Select|Wrap|Line Numbers
  1.    Taxi taxis[]=new Taxi[20];        // create the array
  2.    for (int i=0;i<taxis.length;i++)
  3.       taxis[i]=new Taxi(.....);      // populate it wil Taxi objects
  4.  
Please assist me with the part B of the questions as I have done the part A.
Your prompt response is appreciated.
regards
Here is the part A
[code]
public class Vehicle {
private String plateNumber;
private String brandName;
private double vehiclePrice;
private double vehicleSpeed;
private String modelType;
private int yearManufacture;



public void setPlateNum(String plateNumber) {
this.plateNumber = plateNumber;
}

public void setBrandName(String brandName) {
this.brandName = brandName;
}

public void setVehiclePrice(double vehiclePrice) {
vehiclePrice = vehiclePrice;
}

public void setVehicleSpeed(double vehicleSpeed) {
this.vehicleSpeed = vehicleSpeed;
}

public void setModelType(String modelType) {
this.modelType = modelType;
}

public void setYearManufacture(int yearManufacture) {
this.yearManufacture = yearManufacture;
}

public String getPlateNum() {
return this.plateNumber;
}

public String getBrandName() {
return this.brandName;
}

public double getVehiclePrice() {
return this.vehiclePrice;
}

public double getVehicleSpeed() {
return this.vehicleSpeed;
}

public String getModelType() {
return this.modelType;
}

public int getYearManufacture() {
return this.yearManufacture;
}
}


class Taxi extends Vehicle {
private String tRegNum;
private String tCompany;

public void setTRegNum(String tRegNum) {
this.tRegNum = tRegNum;
}

public void setTCompany(String tCompany) {
this.tCompany = tCompany;
}

public String getTRegNum() {
return this.tRegNum;
}

public String getTCompany() {
return this.tCompany;
}
}
[code]
Feb 28 '07 #6
r035198x
13,262 8TB
Please assist me with the part B of the questions as I have done the part A.
Your prompt response is appreciated.
regards
Here is the part A
[code]
public class Vehicle {
private String plateNumber;
private String brandName;
private double vehiclePrice;
private double vehicleSpeed;
private String modelType;
private int yearManufacture;



public void setPlateNum(String plateNumber) {
this.plateNumber = plateNumber;
}

public void setBrandName(String brandName) {
this.brandName = brandName;
}

public void setVehiclePrice(double vehiclePrice) {
vehiclePrice = vehiclePrice;
}

public void setVehicleSpeed(double vehicleSpeed) {
this.vehicleSpeed = vehicleSpeed;
}

public void setModelType(String modelType) {
this.modelType = modelType;
}

public void setYearManufacture(int yearManufacture) {
this.yearManufacture = yearManufacture;
}

public String getPlateNum() {
return this.plateNumber;
}

public String getBrandName() {
return this.brandName;
}

public double getVehiclePrice() {
return this.vehiclePrice;
}

public double getVehicleSpeed() {
return this.vehicleSpeed;
}

public String getModelType() {
return this.modelType;
}

public int getYearManufacture() {
return this.yearManufacture;
}
}


class Taxi extends Vehicle {
private String tRegNum;
private String tCompany;

public void setTRegNum(String tRegNum) {
this.tRegNum = tRegNum;
}

public void setTCompany(String tCompany) {
this.tCompany = tCompany;
}

public String getTRegNum() {
return this.tRegNum;
}

public String getTCompany() {
return this.tCompany;
}
}
[code]
Write the test class then and create the array of taxis like horace1 showed you how. Do you have a problem with that?
Mar 1 '07 #7
Write the test class then and create the array of taxis like horace1 showed you how. Do you have a problem with that?
yes i do..please assist
Mar 1 '07 #8
r035198x
13,262 8TB
yes i do..please assist
Well write the class. It doesn't need a constructor. Just put the main method and declare the array and put some taxis in it.
Mar 1 '07 #9
Well write the class. It doesn't need a constructor. Just put the main method and declare the array and put some taxis in it.
Here is the test class TaxiI created..please assist in completing it. thanks
Expand|Select|Wrap|Line Numbers
  1.  class Taxi  
  2. {
  3.  
  4.     private String tRegNum;
  5.     private String tCompany;
  6. }
  7.  
  8. public static void main(String args[])
  9. {
  10.  Taxi taxis[]=new Taxi[20];        
  11.    for (int i=0;i<taxis.length;i++)
  12.       taxis[i]=new Taxi(.....);     
  13. }
  14.  
Mar 1 '07 #10
r035198x
13,262 8TB
Here is the test class TaxiI created..please assist in completing it. thanks
Expand|Select|Wrap|Line Numbers
  1. class Taxi 
  2. {
  3.  
  4.     private String tRegNum;
  5.     private String tCompany;
  6. }
  7.  
  8. public static void main(String args[])
  9. {
  10. Taxi taxis[]=new Taxi[20]; 
  11. for (int i=0;i<taxis.length;i++)
  12. taxis[i]=new Taxi(.....); 
  13. }
  14.  
My dear friend please find time to read this
Mar 1 '07 #11
My dear friend please find time to read this
My dear teacher, i dont have time to read this now cos I am constrained of time. I will definately read this later but need to submit this now. Your prompt response is HIGHLY appreciated.Thanks
Mar 1 '07 #12
r035198x
13,262 8TB
My dear teacher, i dont have time to read this now cos I am constrained of time. I will definately read this later but need to submit this now. Your prompt response is HIGHLY appreciated.Thanks
Write the constructors then
Expand|Select|Wrap|Line Numbers
  1.  
  2. public Vehicle(String plateNumber, String brandName, double vehiclePrice, double vehicleSpeed, String modelType, int yearManufacture) {
  3.  
  4. //initialize all of them here
  5. }
  6.  
and
Expand|Select|Wrap|Line Numbers
  1.  public Vehicle() { 
  2. //initialize everyting to default values
  3. }
  4.  
Do the same for taxi and use these constructors to initialize these values and then initialize those for the other unique attributes in Taxi.

now in main you can do



Expand|Select|Wrap|Line Numbers
  1.  Taxi[] taxis = new Taxi[5];
to create space for 5 taxis then


Expand|Select|Wrap|Line Numbers
  1.  
  2. Taxi taxi1 = new Taxi("001", "BMW", 5000.0, 500.0, "X5", 200);
  3.  
to create a taxi and

Expand|Select|Wrap|Line Numbers
  1. taxis[0] = taxi1;
to set this taxi as the first element of the array.

Now get to work quickly
Mar 1 '07 #13
Write the constructors then
Expand|Select|Wrap|Line Numbers
  1.  
  2. public Vehicle(String plateNumber, String brandName, double vehiclePrice, double vehicleSpeed, String modelType, int yearManufacture) {
  3.  
  4. //initialize all of them here
  5. }
  6.  
and
Expand|Select|Wrap|Line Numbers
  1.  public Vehicle() { 
  2. //initialize everyting to default values
  3. }
  4.  
Do the same for taxi and use these constructors to initialize these values and then initialize those for the other unique attributes in Taxi.

now in main you can do



Expand|Select|Wrap|Line Numbers
  1.  Taxi[] taxis = new Taxi[5];
to create space for 5 taxis then


Expand|Select|Wrap|Line Numbers
  1.  
  2. Taxi taxi1 = new Taxi("001", "BMW", 5000.0, 500.0, "X5", 200);
  3.  
to create a taxi and

Expand|Select|Wrap|Line Numbers
  1. taxis[0] = taxi1;
to set this taxi as the first element of the array.

Now get to work quickly

Here is what i waz able to do but is came up with error of cannot find find symbol
symbol: variable toString

Please assist with the remaining two questions. I have run out of time.
Thansks

Expand|Select|Wrap|Line Numbers
  1. class Vehicle
  2. {
  3. String plateNumber; String brandName; double vehiclePrice; double vehicleSpeed; String licenseno;
  4. }  
  5.  
  6. public class Taxi extends Vehicle
  7. {
  8.  
  9. public Taxi(String plateNumber, String brandName, double vehiclePrice, double vehicleSpeed, String licenseno)
  10. {
  11. this.plateNumber = plateNumber;
  12. this.brandName = brandName;
  13. this.vehiclePrice=vehiclePrice;
  14. this.vehicleSpeed=vehicleSpeed; 
  15. this.licenseno=licenseno;
  16. }
  17.  
  18.  
  19.  
  20.  
  21. public static void main(String args[])
  22. {
  23. int i=0;
  24. Taxi[] taxis = new Taxi[5];
  25. Taxi taxi1 = new Taxi("001", "Toyota", 5000.0, 500.0, "GDG5364KK");
  26. taxis[0] = taxi1;
  27. System.out.println(taxi1.toString);
  28. }
  29.  
  30. }
  31.  
Mar 2 '07 #14
Ganon11
3,652 Expert 2GB
The error received is due to the fact that you used:
Expand|Select|Wrap|Line Numbers
  1. System.out.println(taxi1.toString); // Variable toString
instead of

Expand|Select|Wrap|Line Numbers
  1. System.out.println(taxi1.toString()); // Function toString()
Mar 2 '07 #15
The error received is due to the fact that you used:
Expand|Select|Wrap|Line Numbers
  1. System.out.println(taxi1.toString); // Variable toString
instead of

Expand|Select|Wrap|Line Numbers
  1. System.out.println(taxi1.toString()); // Function toString()
Thanks
are u helping me with the remaining 2 questions?
I await your response
Mar 2 '07 #16
The error received is due to the fact that you used:
Expand|Select|Wrap|Line Numbers
  1. System.out.println(taxi1.toString); // Variable toString
instead of

Expand|Select|Wrap|Line Numbers
  1. System.out.println(taxi1.toString()); // Function toString()
when i run the Taxi.java file after compiling it reads "Taxi@82ba41"
How do i make the code return the contents of methods
Expand|Select|Wrap|Line Numbers
  1. Taxi taxi1 = new Taxi("001", "Toyota", 5000.0, 500.0, "Camry");
  2.  
please reply fast
rgds
Mar 2 '07 #17
r035198x
13,262 8TB
when i run the Taxi.java file after compiling it reads "Taxi@82ba41"
How do i make the code return the contents of methods
Expand|Select|Wrap|Line Numbers
  1. Taxi taxi1 = new Taxi("001", "Toyota", 5000.0, 500.0, "Camry");
  2.  
please reply fast
rgds
Inside taxi class put

the method

Expand|Select|Wrap|Line Numbers
  1.  public String toString() { 
  2.            return "Plate :"+plateNumber+" Brand:"+brandName+"  Price:"+vehiclePrice;
  3. }
  4.  
Mar 2 '07 #18
Inside taxi class put

the method

Expand|Select|Wrap|Line Numbers
  1.  public String toString() { 
  2.            return "Plate :"+plateNumber+" Brand:"+brandName+"  Price:"+vehiclePrice;
  3. }
  4.  
Thanks it worked!
Kindly assist me on how to complete the below:

Develop a Java program that makes use of array to store the Taxi information. This program must have features to the program in Part A with the following specifications:

i. The program can display the average taxi price.
ii. The program can store new taxis inside the array.
iii. The program can search for particular taxi information.
iv. Any two features other than those stated in part A and B.

Urgent respnse required please
thanks
Mar 2 '07 #19
r035198x
13,262 8TB
Thanks it worked!
Kindly assist me on how to complete the below:

Develop a Java program that makes use of array to store the Taxi information. This program must have features to the program in Part A with the following specifications:

i. The program can display the average taxi price.
ii. The program can store new taxis inside the array.
iii. The program can search for particular taxi information.
iv. Any two features other than those stated in part A and B.

Urgent respnse required please
thanks
Expand|Select|Wrap|Line Numbers
  1.  public static double getAveragePrice(Taxi[] taxis) { 
  2. //loop through all the taxis adding the price to a variable
  3. }
  4.  
Now do that quickly
Mar 2 '07 #20
Expand|Select|Wrap|Line Numbers
  1.  public static double getAveragePrice(Taxi[] taxis) { 
  2. //loop through all the taxis adding the price to a variable
  3. }
  4.  
Now do that quickly
please guide on how to start the looping... i dont know looping please assist
Mar 2 '07 #21
Expand|Select|Wrap|Line Numbers
  1.  public static double getAveragePrice(Taxi[] taxis) { 
  2. //loop through all the taxis adding the price to a variable
  3. }
  4.  
Now do that quickly
please guide on how to start the looping... i dont know looping please assist. I am waiting on you.thx
Mar 2 '07 #22
r035198x
13,262 8TB
please guide on how to start the looping... i dont know looping please assist. I am waiting on you.thx

http://www.cafeaulait.org/course/week2/32.html
Mar 2 '07 #23

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

Similar topics

22
by: edgrsprj | last post by:
PROPOSED EARTHQUAKE FORECASTING COMPUTER PROGRAM DEVELOPMENT EFFORT Posted July 11, 2005 My main earthquake forecasting Web page is: http://www.freewebz.com/eq-forecasting/Data.html ...
0
by: Tom Lee | last post by:
Hi, I'm new to .NET 2003 compiler. When I tried to compile my program using DEBUG mode, I got the following errors in the C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7 \include\xdebug...
11
by: christopher diggins | last post by:
I am wondering if any can point me to any open-source library with program objects for C++ like there is in Java? I would like to be able to write things like MyProgram1 >> MyProgram2 >>...
1
by: Eric Whittaker | last post by:
hi all, im trying to write my first c++ program. a success, but i can't get the window to stay open after user enters input. it just automatically closes. right now the end of my program looks...
9
by: Hemal | last post by:
Hi All, I need to know the memory required by a c program. Is there any tool/utility which can give me the memory usage in terms of DATA segment, TEXT segment, BSS segment etc. I am working...
7
by: ibtc209 | last post by:
I just started programming in C, and I need some help with this problem. Your program will read the information about one MiniPoker hand, namely the rank and suit of the hand’s first card, and...
6
by: xdeath | last post by:
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...
2
Banfa
by: Banfa | last post by:
Posted by Banfa The previous tutorial discussed what programming is, what we are trying to achieve, the answer being a list of instructions constituting a valid program. Now we will discuss how...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.