Results 1 to 6 of 6
  1. #1
    border9 is offline Member
    Join Date
    Jan 2009
    Posts
    1
    Rep Power
    0

    Default Classes and Methods help

    My professor is kinda awful, and I have no idea what he wants or how to do what he is asking. Here are the instructions.

    Java Code:
    Write a Java class named "Car" that models an automobile. The class should include the following instance variables (all String objects):
    
    * maker (e.g., Ford, Toyota, etc.)
    * model (e.g., Fusion, Camry, etc.)
    * cylinders (normally an integer but we will use a string representation for now)
    * color
    
    Your class should include the following methods:
    
    * default constructor
    * initialization constructor with the parameters passed in the same order as given above (maker, model, cylinders, color)
    * copy constructor
    * setter method for each instance variable (setMaker, setModel, setCylinders, setColor)
    * getter method for each instance variable (getMaker, getModel, getCylinders, getColor)
    * toString method (you may choose your own string representation).
    
    Your class file should include appropriate documentation comments for the class as a whole and for each method. The Java class implementation is worth 10 points and appropriate documentation comments are worth an additional 5 points.
    
    any help as well as the proper coding is appreciated.
    thanks
    Any help with explanation as well as the proper coding would be extremely appreciated.

  2. #2
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default my help in bold...

    Write a Java class named "Car" that models an automobile.
    public class Car{ ... }

    The class should include the following instance variables (all String objects):
    * maker (e.g., Ford, Toyota, etc.)
    String maker;
    * model (e.g., Fusion, Camry, etc.)
    String model;
    * cylinders (normally an integer but we will use a string representation for now)
    String cylinders;
    * color
    String color;


    Your class should include the following methods:

    * default constructor
    public Car(){...}

    * initialization constructor with the parameters passed in the same order as given above (maker, model, cylinders, color)

    public Car(String maker,String model,... cylinders,... color){
    this.maker = maker;
    ...
    }


    * copy constructor
    ?? forgot what this is... ??

    * setter method for each instance variable (setMaker, setModel, setCylinders, setColor)
    thats a given

    * getter method for each instance variable (getMaker, getModel, getCylinders, getColor)
    thats also a given

    * toString method (you may choose your own string representation).
    a design choice

    Your class file should include appropriate documentation comments for the class as a whole and for each method.
    meaning to use /** @param stuff */

    The Java class implementation is worth 10 points and appropriate documentation comments are worth an additional 5 points.
    meaning bs
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  3. #3
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    oh that look really sloppy....
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  4. #4
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    A "copy constructor" takes another instance of Car as a parameter and initializes the new instance properties with the instance properties of the one passed as a parameter.

  5. #5
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default something like this?

    Java Code:
    public Car(Car c){
      this.model = c.getModel();
      ...
    }
    then getModel() should be:
    Java Code:
    public String getModel(){
      return model.clone();
    }
    Last edited by angryboy; 01-30-2009 at 06:51 PM.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  6. #6
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    i think that works in most cases, but some more complex classes might have more going on behind the scenes that requires initialization and not just copying parameters available with get-methods.

Similar Threads

  1. Replies: 8
    Last Post: 04-16-2012, 11:00 PM
  2. Replies: 3
    Last Post: 10-12-2008, 02:49 PM
  3. How to call methods of different classes
    By adeeb in forum New To Java
    Replies: 2
    Last Post: 06-06-2008, 06:08 AM
  4. Replies: 1
    Last Post: 04-17-2008, 02:30 PM

Posting Permissions

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