Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Importing Scanner
- import java.util.Scanner;
- // Electric Fan class
- public class ElectricFan {
- // Instance variables
- double Size;
- int Speed;
- int PowerStatus;
- int Rotating;
- int Status;
- // Default Constructor method
- public ElectricFan() {
- }
- // Constructor method
- public ElectricFan() {
- // Instantiating Scanner
- Scanner Input = new Scanner(System.in);
- // Requesting to input the size of the fan as well as storing it for later use.
- System.out.print("Enter the size of your electric fan in centimetres: ");
- this.Size = Input.nextDouble();
- // Requesting to input the speed of the fan which is an integer as it will be processed to print a string.
- System.out.print("Enter the speed of your electric fan which ranges between 1 and 3: ");
- this.Speed = Input.nextInt();
- // Requesting to input the power status of the fan which is an integer as it will be processed to print a string.
- System.out.print("To switch on the fan, type 1 and to switch it off, type 0: ");
- this.PowerStatus = Input.nextInt();
- // Requesting to input whether or not the fan will rotate which is an integer as it will be processed to print a string.
- System.out.print("To set the rotation of the fan, type 1 and to stop the rotation of the fan, type 0: ");
- this.Rotating = Input.nextInt();
- // Requesting to input whether or not the fan is in a good status which is an integer as it will be processed to print a string.
- System.out.print("To set the status of the fan, type 1 for a faulty fan and type 0 for a perfectly functional fan: ");
- this.Status = Input.nextInt();
- }
- // Size accessor method
- public double getSize() {
- return this.Size;
- }
- // Size mutator method
- public void setSize(double ElectricFanSize) {
- ElectricFanSize = this.Size;
- }
- // Speed accessor method
- public int getSpeed() {
- return this.Speed;
- }
- // Speed mutator method
- public void setSpeed(int ElectricFanSpeed) {
- ElectricFanSpeed = this.Speed;
- }
- // Power Status accessor method
- public int getPowerStatus() {
- return this.PowerStatus;
- }
- // Power Status mutator method
- public void setPowerStatus(int ElectricFanPowerStatus) {
- ElectricFanPowerStatus = this.PowerStatus;
- }
- // Rotating accessor method
- public int getRotating() {
- return this.Rotating;
- }
- // Rotating mutator method
- public void setRotating(int ElectricFanRotating) {
- ElectricFanRotating = this.Rotating;
- }
- // Status accessor method
- public int getStatus() {
- return this.Status;
- }
- // Status mutator method
- public void setStatus(int ElectricFanStatus) {
- ElectricFanStatus = this.Status;
- }
- // Switch On method
- public void SwitchOn() {
- // Checking whether the electric fan is on in order to switch it on.
- if (this.getPowerStatus() == 0) {
- this.setPowerStatus(1);
- } else {
- System.out.println("The electric fan is already on!");
- }
- }
- // Switch Off method
- public void SwitchOff() {
- // Checking whether the electric fan is off in order to switch it off.
- if (this.getPowerStatus() == 1) {
- this.setPowerStatus(0);
- } else {
- System.out.println("The electric fan is already off!");
- }
- }
- // Change Speed method
- public void ChangeSpeed() {
- int Speed;
- // Instantiating Scanner
- Scanner Input = new Scanner(System.in);
- // Switch for choosing speed.
- switch (true) {
- case 1:
- if (this.getSpeed() == 1) {
- System.out.println("The speed of the fan is already " + this.getSpeed() + ".");
- } else {
- System.out.print("Choose your speed Between 1 and 3: ");
- Speed = Input.nextInt();
- }
- break;
- case 2:
- if (this.getSpeed() == 2) {
- System.out.println("The speed of the fan is already " + this.getSpeed() + ".");
- } else {
- System.out.print("Choose your speed Between 1 and 3: ");
- Speed = Input.nextInt();
- }
- break;
- case 3:
- if (this.getSpeed() == 3) {
- System.out.println("The speed of the fan is already " + this.getSpeed() + ".");
- } else {
- System.out.print("Choose your speed Between 1 and 3: ");
- Speed = Input.nextInt();
- }
- break;
- default:
- System.out.println("It is no use of changing the speed at this moment.");
- }
- // Instantiating Scanner
- // Scanner SpeedInput = new Scanner(System.in);
- // // Answer will be used to access the conditions to change the speed of the fan.
- // int Answer;
- // System.out.print("If, you want to change the speed, type 0 for No and type 1 for Yes: ");
- // Answer = SpeedInput.nextInt();
- // if (Answer == 1) {
- // System.out.print("Choose the speed that you want between 1, 2 and 3: ");
- // int ChangeSpeedSpeed = SpeedInput.nextInt();
- // // Assigning the Speed variable of ChangeSpeed method.
- // this.setSpeed(ChangeSpeedSpeed);
- // } else {
- // System.out.println("The speed cannot be changed!");
- // }
- }
- // Rotate method
- public void Rotate() {
- // Instantiating Scanner
- Scanner RotateInput = new Scanner(System.in);
- // Answer will be used to access the conditions to rotate or stabilise he fan.
- int Answer;
- System.out.print("If, you want to change the speed, type 0 for No and type 1 for Yes: ");
- Answer = RotateInput.nextInt();
- // Conditions to rotate the fan.
- if (Answer == 1) {
- System.out.print("Choose 1 for rotating fan or choose 0 for a stable fan: ");
- int RotateRotation = RotateInput.nextInt();
- this.setRotating(RotateRotation);
- if (this.getRotating() == 0) {
- System.out.println("The fan is not rotating!");
- } else {
- System.out.println("The fan is rotating!");
- }
- } else {
- System.out.println("The rotation of the fan cannot be changed!");
- }
- }
- // Change Status method
- public void ChangeStatus() {
- // Instantiating Scanner
- Scanner ChangeStatusInput = new Scanner(System.in);
- // Answer will be used to access the conditions to rotate or stabilise he fan.
- int Answer;
- System.out.print("If, you want to change the status of the fan, type 0 for No and type 1 for Yes: ");
- Answer = ChangeStatusInput.nextInt();
- // Conditions to rotate the fan.
- if (Answer == 1) {
- System.out.println("Is the fan faulty?");
- String ChangeStatusStatus = ChangeStatusInput.next();
- if (ChangeStatusStatus == "Yes" || ChangeStatusStatus == "yes") {
- if (this.getStatus() == 0) {
- this.setStatus(1);
- } else if (this.getStatus() == 1) {
- this.setStatus(0);
- }
- } else {
- if (this.getStatus() == 0) {
- System.out.println("The fan is perfectly fine!");
- } else if (this.getStatus() == 1) {
- System.out.println("The fan is faulty!");
- }
- }
- } else {
- System.out.println("The status of the fan cannot be changed!");
- }
- }
- // Setting Speed method
- public String SettingSpeed() {
- String SettingSpeedStatus;
- if (this.getSpeed()) {
- } else if (2) {
- } else if (3) {
- }
- return SettingSpeedStatus;
- }
- // Display method
- public void Display() {
- System.out.println("Size: " + String.format("%.3f", this.getSize()) + " cm.");
- System.out.println("Size: " + String.format("%.3f", this.getSize()) + " cm.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement