Hello,

First I'll like to say that this a fantastic site for newbies and I'm sure for seasoned programmers as well. I have gained a lot of insight by just reading the threads and for this I thank Daniweb.

Thank you very much in advance for your expert help.

My assignment is to creat 3 classes. All variables are private.

1) Customer class with - variables customername and customernum

2) Vehicle class - variables make, model, year and price

For 1 and 2 need methods - get, set, and default constructor

3) Create a Dealership class - variables slaesmanname
The salesman variable is private. Variable vehicles[] array of 5 vehicles

public class Customer {

    //declare instance variable
    private String customername;  //name of customer
    private int customernum;      //customer number


     //Constructors
      Customer()
      {   customername = "";
          customernum = 0;
      }

      Customer(String n, int c)
      {  customername = n;
         customernum = c;

      }

      //getters
      {    String getCustomername()
           {    return customername;  }
           int getCustomernum()
           {    return customernum;   }
      }

    //setters
      {    void setCustomername(String n)
           {    customername = n;  }
           void setCustomernum()
           {    customernum = c;   }
      }

      }
      }

------------------------------------------------------------------------------- 



public class Vehicle {
//declare variables
          private float price;  //price 
          private int year;     //year
          private String make;  //make
          private String model; //model

          //Constructors
          Vehicle()
          {   price = 0.00f;
              year  = 0;
              make  = "";
              model = "";
          }

          Vehicle(float p, int y, String m, String d)
          {  price = p;
             year  = y;
             make  = m;
             model = d;
          }
          //declare methods


           {     float getPrice()
                 {     return price;   }
                 String getMake()
                 {     return make;  }
                 }



           {     void setPrice(float p)
                 {     price = p;   }
                 void setMake(String m)
                 {     make = m;  }
}

-----------------------------------------------------------------------------------------
public class Salesman {

    //declare variables
      private String salesmanname;  //name of sales person
}
      //Constructors
      Salesman()
      {   salesmanname = "";

      }

      Salesman(String m)
      {  salesmanname = ("Joe Black");       
}
------------------------------------------------------------------------------------------
public class Dealership {

        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            //declare instance variable
                    //array of Vehicles

               Vehicle v = new Vehicle();
            Vehicle vehicles [] = new Vehicle[5]; int i;
            vehicles[0].initializeVehicle(18000.00f, 2007, "Nissan", "Sentra");
            vehicles[1].initializeVehicle(33000.00f, 2008, "Ford", "Mustang");
            vehicles[2].initializeVehicle(25000.00f, 2009, "Chrysler", "Cherokee");
            vehicles[3].initializeVehicle(40000.00f, 2007, "Ford", "F150");
            vehicles[4].initializeVehicle(30000.00f, 2008, "Nissan", "Pathfinder");

                    //Loop through the array

                    for (int i = 0; i,5; 1++
                    {    if(v == vehicles[i].vehicle)
                        {     found = true;
                              match = i;
                              break;
                        }
                         else
                        {     found  =  false;
                        }
                    }
              Salesman s = new Salesman();


}

what is your question? also please post code in code tags, much easier on the eyes

Vehicle vehicles [] = new Vehicle[5]; int i;
vehicles[0].initializeVehicle(18000.00f, 2007, "Nissan", "Sentra");

vehicles[0] is null. You need to do:
vehicles[0] = new Vehicle();
or
vehicles[0] = new Vehicle(price, year, make , model);

Also, I could not find where the initializeVehicle method is declared. It should be put in the Vehicle class if you want to call it like this


The rest of the code is a mess

Also the SAME way the Vehicle has price and year,
The DealerShip class will have private variables: private Salesman salesman; and Vehicle [] vehicles = new Vehicle[5]; And you will use get, set methods for the above. NO main method is required.

Thank you very much

Vehicle vehicles [] = new Vehicle[5]; int i;
vehicles[0].initializeVehicle(18000.00f, 2007, "Nissan", "Sentra");

vehicles[0] is null. You need to do:
vehicles[0] = new Vehicle();
or
vehicles[0] = new Vehicle(price, year, make , model);

Also, I could not find where the initializeVehicle method is declared. It should be put in the Vehicle class if you want to call it like this


The rest of the code is a mess

Also the SAME way the Vehicle has price and year,
The DealerShip class will have private variables: private Salesman salesman; and Vehicle [] vehicles = new Vehicle[5]; And you will use get, set methods for the above. NO main method is required.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.