Friday, October 28, 2011

Messages & Sending Messages


Messages

Messages

1.  Write the code for invoking a method named sendSignal.  There are no arguments for this method.
Assume that sendSignal is defined in the same class that calls it.

sendSignal() ;

2.  Write the code for invoking a method named sendNumber.  There is one int argument for this method.  Send the number 5 as an argument to this method.
Assume that sendNumber is defined in the same class that calls it.

sendNumber(5) ;


3.  Write the code for invoking a method named  sendVariable.  There is one int argument for this method.
Assume that an int variable called x has already been declared and initialized to some value.  Use this variable's value as an argument in your method invocation.
Assume that sendVariable is defined in the same class that calls it.

sendVariable(x) ;



4.  Write the code for invoking a method named sendTwo.  There are two arguments for this method:  a double and an int.  Invoke the method with the double value of 15.955 and the int value of 133.
Assume that sendTwo is defined in the same class that calls it.

sendTwo(15.955,133) ;


5.  Write the code for invoking a method named sendObject.  There is one argument for this method which is of type Customer.
Assume that there is a reference to an object of type Customer, in a variable called John_Doe.  Use this reference as your argument.
Assume that sendObject is defined in the same class that calls it.

sendObject(John_Doe) ;


Sending_Messages

1.  Assume there is a class AirConditioner that supports the following behaviors:  turning the air conditioner on and off.  The following methods are provide this behavior:  turnOn and turnOff.  Both methods take no arguments and return no value.
Assume there is a reference variable myAC to an object of this class, which has already been created.  Using the reference variable, invoke a method to tell the air conditioner object to turn on.
Example:  So, as a result of your code executing, the turnOn() method of the AirCondition object that myAC refers to will be invoked.


myAC.turnOn() ;


2.  Assume there is a class AirConditioner that supports the following behaviors:  turning the air conditioner on and off.  The following methods are provide this behavior:  turnOn and turnOff.  Both methods take no arguments and return no value.

Assume there is a reference variable myAC to an object of this class, which has already been created.  Using the reference variable, invoke a method to tell the air conditioner objection to turn off.

myAC.turnOff() ;


3.  Assume there is a class AirConditioner that supports the following behaviors:  turning the air conditioner on and off, and setting the desired temperature.  The following methods provide this behavior:  turnOn and turnOff, and setTemp, which accepts an int argument and returns no value.

Assume there is a reference variable myAC to an object of this class, which has already been created.  Use the reference variable, to invoke a method that tells the object to set the air conditioner to 72 degrees.

myAC.setTemp(72) ;


4.  Assume there is a class AirConditioner that supports the following behaviors:  turning the air conditioner on and off, setting the desired temperature, and reporting the previously set temperature.
The following methods provide this behavior:  turnOn and turnOff, setTemp, which accepts an int argument and returns no value, and getTemp, which accepts no value and returns an int.

Assume there is a reference variable myAC to an object of this class, which has already been created.  There is also an int variable called currentTemp, which has already been declared.  Use the reference variable, to invoke a method to retrieve the previously set temperature and store the returned value in currentTemp.

currentTemp = myAC.getTemp() ;


5.  Assume there is a class AirConditioner that supports the following behaviors:  turning the air conditioner on and off, and checking if the air conditioner is on or off.
The following methods provide this behavior:  turnOn and turnOff, setTemp, and isOn, which accepts no argument and returns a boolean indicating whether the air conditioner is on or off.


Assume there is a reference variable myAC to an object of this class, which has already been created.  There is also a boolean variable status, which has already been declared.  Use the reference variable, to invoke a method to find out whether the air conditioner is on and store the result in status.

status = myAC.isOn() ;


6.  Assume there is a class AirConditioner that supports the following behaviors:  turning the air conditioner on and off.  The following methods provide these behaviors:  turnOn and turnOff.  Both methods accept no arguments and return no value.

Assume there is a reference variable officeAC of type AirConditioner.  Create a new object of type AirConditioner and save the reference in officeAC.  After that, turn the air conditioner on using the reference to the new object.

officeAC = new AirConditioner() ;
officeAC.turnOn() ;


7.  Assume there is a class AirConditioner that supports the following behaviors:  turning the air conditioner on and off, and setting the desired temperature.  The following methods provide these behaviors:  turnOn and turnOff, which accept no arguments and return no value, and setTemp, which accepts an int argument and returns no value.

Assume there is a reference variable officeAC of type AirConditioner.  Create a new object of type AirConditioner and save the reference in officeAC.  After that, use the reference to turn on the new air conditioner object and set the desired temperature to 69 degrees.

officeAC = new AirConditioner() ;
officeAC.turnOn() ;
officeAC.setTemp(69) ;






4 comments:

  1. Can you please help me with this problem?

    A BufferedReader has a constructor  that takes a single InputStreamReader parameter . InputStreamReader has a constructor  that takes a single InputStream parameter . Suppose  there is a class  WidgetInputStream that is a subclass of InputStream and suppose  there is variable , wis, that refers to a WidgetInputStream object . Write an expression  whose value  is a reference  to a newly created BufferedReader that is based on the WidgetInputStream object  wis refers to.

    ReplyDelete
  2. new BufferedReader (new InputStreamReader(wis));

    ReplyDelete
  3. Given  four int variables  that have been declared  and given  values , octet1, octet2, octet3, and octet4, write a String  expression  whose value  is the String  equivalent of each these variables  joined by a single period (.) So if octet1, octet2, octet3, and octet4, had the values  129, 42, 26, and 212 the expression 's value  would be "129.42.26.212". Alternatively, if octet1, octet2, octet3, and octet4, had the values  192, 168, 1and 44 the expression 's value  would be "192.168.1.44".
    and
    Given  three String variables  that have been declared  and given  values , firstName, middleName, and lastName, write an expression  whose value  is the initials of the three names : the first letter of each, joined together. So if firstName, middleName, and lastName, had the values  "John", "Fitzgerald", and "Kennedy", the expression 's value  would be JFK". Alternatively, if firstName, middleName, and lastName, had the values  "Franklin", "Delano", and "Roosevelt", the expression 's value  would be "FDR".

    ReplyDelete
  4. Need help with a python 3.3 program using functions, A county collects property taxes on the assessment value of property, which is 60percent of the property's actual value. For example, if an acre of land is valued at $10,0000, it's assessment is $6,000. The property tax is then .64cent for each $100 of the assessment value. The tax for the acre assessed at $6,000 will be $38.40. Write a program that asks for the actual value of a piece of property and displays the assessment value and property tax.

    ReplyDelete