Ask Experts Questions for FREE Help !
Ask
    m4ssiv3's Avatar
    m4ssiv3 Posts: 3, Reputation: 1
    New Member
     
    #1

    Feb 10, 2010, 07:22 AM
    Java questions - I need the answers
    Declare each of the following:
    (a) a field of data type boolean and name isFound;
    (b) a local variable of data type String and name carModel;
    (c) a field of data type double and name weight;
    (d) a field of data type Employee and name secretary.

    2. Write a declaration for an array variable temperatures that could be used to refer
    to an array of double values.
    Give a Java statement to create an array of double elements of size 95 and referenced
    by temperatures.
    What is the index range for this array?
    Write a fragment of code to determine the average temperature in an array, temperatures,
    of temperature readings.
    3. A class Car has the following fields:
    private String registration;
    private int doors;
    private String colour;
    private CarDealer supplier;


    (a) Define a class variable, totalCars, whose purpose is to keep track of the total
    number of Car objects constructed during execution of a program that uses
    the Car class.
    (b) Declare a default constructor for this class.
    (c) Declare a constructor for this class which has a formal parameter corresponding
    to each field.
    (d) Declare an accessor method called getColour whose purpose is to return the
    value of the colour field of this Car.
    (e) Declare a mutator method that sets the registration number of this Car to a
    given value.
    (f) Declare a method to determine whether this Car has a given colour.
    FadedMaster's Avatar
    FadedMaster Posts: 1,510, Reputation: 148
    Ultra Member
     
    #2

    Feb 10, 2010, 07:30 AM

    I would recommend asking your teacher if you need help with homework. ;)
    m4ssiv3's Avatar
    m4ssiv3 Posts: 3, Reputation: 1
    New Member
     
    #3

    Feb 12, 2010, 02:26 PM

    I did them, can anyone tell me if I did them correctly. Also I have know idea for (F)

    1. (a) public boolean isFound;
    (b) String name = carModel;
    (c) private double weight;
    (d) private Employee secretary;

    2. private double [ ] temperatures;

    double[ ] temperatures = new double[95];
    0-94 (n-1)


    double total=0.0, average;
    int size = tempArray.length;
    for ( int index=0; index < size; index++) {
    total += tempArray [ index ];
    } // end for
    average = total / size;

    temperatures [ 0 ] = 0.0;
    lastDay = temperatures[ 364 ];


    3. A class Car has the following fields:
    private String registration;
    private int doors;
    private String colour;
    private CarDealer supplier;

    (a) private static int totalCars = 0;


    (b) Declare a default constructor for this class.

    public Car(String Registration , int doors, String coulour, suppier){

    (c) Declare a constructor for this class which has a formal parameter corresponding
    to each field.

    public Car(String carRegistration , int carDoors, String carCoulour, carSuppier){

    registration = carRegistration;
    doors = carDoors;
    colour = carColour;
    supplier = carSupplier;


    (d) Declare an accessor method called getColour whose purpose is to return the
    value of the colour field of this Car.

    public int getColour()
    {
    return colour;
    }

    (e) Declare a mutator method that sets the registration number of this Car to a
    given value.

    public void setRegistration(String newRegistration)
    {
    registration = newRegistration;
    }

    (f) Declare a method to determine whether this Car has a given colour.
    jmd814's Avatar
    jmd814 Posts: 10, Reputation: 2
    New Member
     
    #4

    Feb 12, 2010, 11:54 PM

    Most of your answers are correct.

    However, 3b is wrong - a default constructor has no parameters.

    As for 3f. Imagine a method where a color is passed into the method and if the car color the parameter are equal then true is returned, otherwise it returns false.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Answers to all questions [ 1 Answers ]

P12-17 Translation, Journal Entries, Consolidated Comprehensive Income, and Stockholders’ Equity On January 1, 20X5, Taft Company acquired all of the outstanding stock of Vikix, Inc. a Norwegian company at a cost of $151,200. Vikix’s net assets on the date of acquisition were 700,000 kroner...

Need answers to questions [ 8 Answers ]

1. What motivates you to put forth your greatest effort? Describe a situation in which you Did so. 2. How do you determine or evaluate success? 3. In what ways do you think you can make a contribution to our organization? 4. Was there an occasion when you disagreed with a...

Questions with no answers [ 2 Answers ]

I am in my early 30's married with no children. I am over weight and have been approved for a lap band because of medical reasons. I am in my fourth month, of "training" for my surgery. The problem is I have questions that just feel stupid. I was wondering if there is any one out there that...


View more questions Search