• All source code files .java in the projects will be created in the default package of the NetBean
Question 1: (2 marks)
Do not pay attention to the real meaning of objects, variables, and their values in the questions below.
Write a class ElectricMotor with the following information:
ElectricMotor
Where:
-name:String
ElectricMotor() - default constructor.
-voltage:int
2 of 3
Paper No: 1
-current:int
+ElectricMotor()
+ElectricMotor(name:String, voltage:int,current:int)
+getName():String
+getPower():int
+setVoltage(voltage:int): void
+toString():String
ElectricMotor(name:String, voltage:int,current:int) parameterized constructor,which sets values to name, voltage and current of the electric motor. If the voltage is greater than 220 or less than 110, set it to 120. If the current is less or equal to 0, set it to 1
getName(): String - return the name
getPower(): int return the motor power,with the power = voltage * current
setVoltage(voltage:int):void update the voltage if the voltage is from 110 to 220
toString():String: return a string format that contains all the information of the ElectricMotor: name, voltage, current,power. The name in uppercase
Zoom
+ 100%
Close