Results 1 to 4 of 4

Thread: Help please :(

  1. #1
    Poor Bee is offline Member
    Join Date
    May 2008
    Posts
    2
    Rep Power
    0

    Unhappy 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:

    1. GetValues() method should assign values for the member variables VehicleNo, ModelYear, ModelName ,BasicPrice and Tax,
    2. CalculatePrice() method should calculate the NetPrice as the sum of the BasicPrice and Tax.
    3. 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 ??

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Java Code:
    public void GetValues( int V,char M,char Mo,int B,int T);
    This is wrong pal. Declaring a method in wrong way. Method not ending with a ; sign. It's used to terminate a statement.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    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);
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •