2. The interface for aclass named Aircond is given below. Nameof class: Aircond Method: switchOn() Description: Ifthe aircond is switched on, the following string will be displayed: "The aircond is already on!" Otherwise,the following string is displayed: "The aircond is on." Method: switchOff() Description: Ifthe aircond is not switched on, the following string will be displayed: "The aircond is already off!" Otherwise,the following string is displayed: "The aircond is off." a. Write a program in steps given below whichmakes use of the above class. i. Write a class named AircondTest which contains just theempty main method. ii. Add statement(s) to create three Aircond objects. iii. Add statement(s) to send a switchOn message to the first and second Aircond objects. iv. Add statement(s) to send a switchOff message to the third Aircond object. v. Add statement(s) to send a switchOn message again to the first andsecond Aircond objects. vi. Add statement(s) to send a switchOff message to the first and third Aircond objects. b. Write the output of the program in (a). 3. The interface for a class named Calculator is described below. For each of the following, write a program which inputs therequired values and uses a Calculatorobject to calculate the given expression. The program then outputs theresult. [10m] Method | | | | | Calculates x+y and returns the result. | | | Calculates x-y and returns the result. | | | Calculates x*y and returns the result. | | | Calculates x/y (real division) and returns the result. | | | Stores x into internal memory | | | Resets internal memory (to zero) | | | Returns value in internal memory | | | Adds x to value in internal memory and stores the result into internal memory. | | | Calculates square root of x and returns the result. | | | Calculates xy and returns the result. |
a. Inputs: floatx, y, z Expression: file:///C:/Users/lenovo/AppData/Local/Temp/msohtmlclip1/01/clip_image002.gif b. Inputs: float k, g, m, x Expression: x+(((m-(k-g))+x)-g) c. Inputs: int t, x, y float k, g Expression: file:///C:/Users/lenovo/AppData/Local/Temp/msohtmlclip1/01/clip_image004.gif d. Inputs: intx, z, m, n Expression: file:///C:/Users/lenovo/AppData/Local/Temp/msohtmlclip1/01/clip_image006.gif 4. Based on the Calculator class in the previous question, determine what the followingprograms calculate. a. calc.memclr(); calc.memsto(calc.add(x, y)); calc.memadd(calc.times(z, y)); System.out.println(calc.memget()); b. calc.memclr(); calc.memsto(calc.add(calc.times(2,x), 1)); calc.memsto(calc.power(calc.add(y,z), calc.memget())); calc.memadd(calc.memget()); System.out.println(calc.memget());
这个是我上课老师给的题目,其实我不是很明白program要我们写出什么...可能英文不太好的关系...有哪位大大可以帮忙解释一下关于问题要的是什么,或者给一下example,不求答案...我只求明白了在自己做而已...谢谢各位大大...
|