Results 1 to 4 of 4
Thread: Help please :(
- 05-02-2008, 12:03 PM #1
Member
- Join Date
- May 2008
- Posts
- 2
- Rep Power
- 0
Help please :(
Am new to java
I have a question in creating an application to declare a class called “Vehicle"
with these required details :
-Instance Member variables: VehicleNo, ModelYear, ModelName, BasicPrice, Tax
-Instance Member functions: GetValues, CalculatePrice and PrintValues.
-All the variables can be declared as private and methods can be declared as public in visibility control.
-Description for the instance member functions:
- GetValues() method should assign values for the member variables VehicleNo, ModelYear, ModelName ,BasicPrice and Tax,
- CalculatePrice() method should calculate the NetPrice as the sum of the BasicPrice and Tax.
- PrintValues() method should display the value of the member variables and NetPrice.
(You are required to choose the correct data type for member variables and signature for methods)
Create your main class with name Question1. The main method, you should create 2 objects of Vehicle class by using default constructor. You are required to use GetValues() method to pass the values for member variables of Vehicle class. You are then required to call the two methods (CalculatePrice(), Printvalues()) to calculate NetPrice and to display the value of member variables and NetPrice for each of the objects created.
........................
I tried to create it but there were LOTS of errors .. am bad in java :(
public class Vehicle
{
private int VehicleNo;
private char ModelYear;
private char ModelName;
private int BasicPrice;
private int Tax;
public void GetValues( int V,char M,char Mo,int B,int T);
{
VehicleNo=V;
ModelYear=M;
ModelName=Mo;
BasicPrice=B;
Tax=T;
}
int CalculatePrice();
{
int NetPrice;
Netprice=BasicPrice+Tax;
return(NetPrice);
}
}
.....
anyone can help ??
- 05-02-2008, 12:08 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Nice attempt pal. :)
Ok, what error you get there?
- 05-02-2008, 12:10 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
This is wrong pal. Declaring a method in wrong way. Method not ending with a ; sign. It's used to terminate a statement.Java Code:public void GetValues( int V,char M,char Mo,int B,int T);
- 05-02-2008, 12:13 PM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You have to learn a lot pal. ;)
Java Code:public class Vehicle { private int VehicleNo; private char ModelYear; private char ModelName; private int BasicPrice; private int Tax; public void GetValues( int V,char M,char Mo,int B,int T) { VehicleNo = V; ModelYear = M; ModelName = Mo; BasicPrice = B; Tax = T; } public int CalculatePrice() { return ( BasicPrice + Tax); } }


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks