Advertisement
Darkness4869

ElectircFan

Sep 2nd, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.36 KB | None | 0 0
  1. // Importing Scanner
  2. import java.util.Scanner;
  3. // Electric Fan class
  4. public class ElectricFan {
  5.     // Instance variables
  6.     double Size;
  7.     int Speed;
  8.     int PowerStatus;
  9.     int Rotating;
  10.     int Status;
  11.     // Default Constructor method
  12.     public ElectricFan() {
  13.        
  14.     }
  15.     // Constructor method
  16.     public ElectricFan() {
  17.         // Instantiating Scanner
  18.         Scanner Input = new Scanner(System.in);
  19.         // Requesting to input the size of the fan as well as storing it for later use.
  20.         System.out.print("Enter the size of your electric fan in centimetres: ");
  21.         this.Size = Input.nextDouble();
  22.         // Requesting to input the speed of the fan which is an integer as it will be processed to print a string.
  23.         System.out.print("Enter the speed of your electric fan which ranges between 1 and 3: ");
  24.         this.Speed = Input.nextInt();
  25.         // Requesting to input the power status of the fan which is an integer as it will be processed to print a string.
  26.         System.out.print("To switch on the fan, type 1 and to switch it off, type 0: ");
  27.         this.PowerStatus = Input.nextInt();
  28.         // Requesting to input whether or not the fan will rotate which is an integer as it will be processed to print a string.
  29.         System.out.print("To set the rotation of the fan, type 1 and to stop the rotation of the fan, type 0: ");
  30.         this.Rotating = Input.nextInt();
  31.         // 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.
  32.         System.out.print("To set the status of the fan, type 1 for a faulty fan and type 0 for a perfectly functional fan: ");
  33.         this.Status = Input.nextInt();
  34.     }
  35.     // Size accessor method
  36.     public double getSize() {
  37.         return this.Size;
  38.     }
  39.     // Size mutator method
  40.     public void setSize(double ElectricFanSize) {
  41.         ElectricFanSize = this.Size;
  42.     }
  43.     // Speed accessor method
  44.     public int getSpeed() {
  45.         return this.Speed;
  46.     }
  47.     // Speed mutator method
  48.     public void setSpeed(int ElectricFanSpeed) {
  49.         ElectricFanSpeed = this.Speed;
  50.     }
  51.     // Power Status accessor method
  52.     public int getPowerStatus() {
  53.         return this.PowerStatus;
  54.     }
  55.     // Power Status mutator method
  56.     public void setPowerStatus(int ElectricFanPowerStatus) {
  57.         ElectricFanPowerStatus = this.PowerStatus;
  58.     }
  59.     // Rotating accessor method
  60.     public int getRotating() {
  61.         return this.Rotating;
  62.     }
  63.     // Rotating mutator method
  64.     public void setRotating(int ElectricFanRotating) {
  65.         ElectricFanRotating = this.Rotating;
  66.     }
  67.     // Status accessor method
  68.     public int getStatus() {
  69.         return this.Status;
  70.     }
  71.     // Status mutator method
  72.     public void setStatus(int ElectricFanStatus) {
  73.         ElectricFanStatus = this.Status;
  74.     }
  75.     // Switch On method
  76.     public void SwitchOn() {
  77.         // Checking whether the electric fan is on in order to switch it on.
  78.         if (this.getPowerStatus() == 0) {
  79.             this.setPowerStatus(1);
  80.         } else {
  81.             System.out.println("The electric fan is already on!");
  82.         }
  83.     }
  84.     // Switch Off method
  85.     public void SwitchOff() {
  86.         // Checking whether the electric fan is off in order to switch it off.
  87.         if (this.getPowerStatus() == 1) {
  88.             this.setPowerStatus(0);
  89.         } else {
  90.             System.out.println("The electric fan is already off!");
  91.         }
  92.     }
  93.     // Change Speed method
  94.     public void ChangeSpeed() {
  95.         int Speed;
  96.         // Instantiating Scanner
  97.         Scanner Input = new Scanner(System.in);
  98.         // Switch for choosing speed.
  99.         switch (true) {
  100.             case 1:
  101.                 if (this.getSpeed() == 1) {
  102.                     System.out.println("The speed of the fan is already " + this.getSpeed() + ".");
  103.                 } else {
  104.                     System.out.print("Choose your speed Between 1 and 3: ");
  105.                     Speed = Input.nextInt();
  106.                 }
  107.                 break;
  108.             case 2:
  109.                 if (this.getSpeed() == 2) {
  110.                     System.out.println("The speed of the fan is already " + this.getSpeed() + ".");
  111.                 } else {
  112.                     System.out.print("Choose your speed Between 1 and 3: ");
  113.                     Speed = Input.nextInt();
  114.                 }
  115.                 break;
  116.             case 3:
  117.                 if (this.getSpeed() == 3) {
  118.                     System.out.println("The speed of the fan is already " + this.getSpeed() + ".");
  119.                 } else {
  120.                     System.out.print("Choose your speed Between 1 and 3: ");
  121.                     Speed = Input.nextInt();
  122.                 }
  123.                 break;
  124.             default:
  125.                 System.out.println("It is no use of changing the speed at this moment.");
  126.         }
  127.         // Instantiating Scanner
  128.         // Scanner SpeedInput = new Scanner(System.in);
  129.         // // Answer will be used to access the conditions to change the speed of the fan.
  130.         // int Answer;
  131.         // System.out.print("If, you want to change the speed, type 0 for No and type 1 for Yes: ");
  132.         // Answer = SpeedInput.nextInt();
  133.         // if (Answer == 1) {
  134.         //     System.out.print("Choose the speed that you want between 1, 2 and 3: ");
  135.         //     int ChangeSpeedSpeed = SpeedInput.nextInt();
  136.         //     // Assigning the Speed variable of ChangeSpeed method.
  137.         //     this.setSpeed(ChangeSpeedSpeed);
  138.         // } else {
  139.         //     System.out.println("The speed cannot be changed!");
  140.         // }
  141.     }
  142.     // Rotate method
  143.     public void Rotate() {
  144.         // Instantiating Scanner
  145.         Scanner RotateInput = new Scanner(System.in);
  146.         // Answer will be used to access the conditions to rotate or stabilise he fan.
  147.         int Answer;
  148.         System.out.print("If, you want to change the speed, type 0 for No and type 1 for Yes: ");
  149.         Answer = RotateInput.nextInt();
  150.         // Conditions to rotate the fan.
  151.         if (Answer == 1) {
  152.             System.out.print("Choose 1 for rotating fan or choose 0 for a stable fan: ");
  153.             int RotateRotation = RotateInput.nextInt();
  154.             this.setRotating(RotateRotation);
  155.             if (this.getRotating() == 0) {
  156.                 System.out.println("The fan is not rotating!");
  157.             } else {
  158.                 System.out.println("The fan is rotating!");
  159.             }
  160.         } else {
  161.             System.out.println("The rotation of the fan cannot be changed!");
  162.         }
  163.     }
  164.     // Change Status method
  165.     public void ChangeStatus() {
  166.         // Instantiating Scanner
  167.         Scanner ChangeStatusInput = new Scanner(System.in);
  168.         // Answer will be used to access the conditions to rotate or stabilise he fan.
  169.         int Answer;
  170.         System.out.print("If, you want to change the status of the fan, type 0 for No and type 1 for Yes: ");
  171.         Answer = ChangeStatusInput.nextInt();
  172.         // Conditions to rotate the fan.
  173.         if (Answer == 1) {
  174.             System.out.println("Is the fan faulty?");
  175.             String ChangeStatusStatus = ChangeStatusInput.next();
  176.             if (ChangeStatusStatus == "Yes" || ChangeStatusStatus == "yes") {
  177.                 if (this.getStatus() == 0) {
  178.                     this.setStatus(1);
  179.                 } else if (this.getStatus() == 1) {
  180.                     this.setStatus(0);
  181.                 }
  182.             } else {
  183.                 if (this.getStatus() == 0) {
  184.                     System.out.println("The fan is perfectly fine!");
  185.                 } else if (this.getStatus() == 1) {
  186.                     System.out.println("The fan is faulty!");
  187.                 }
  188.             }
  189.         } else {
  190.             System.out.println("The status of the fan cannot be changed!");
  191.         }
  192.     }
  193.     // Setting Speed method
  194.     public String SettingSpeed() {
  195.         String SettingSpeedStatus;
  196.         if (this.getSpeed()) {
  197.            
  198.         } else if (2) {
  199.            
  200.         } else if (3) {
  201.            
  202.         }
  203.         return SettingSpeedStatus;
  204.     }
  205.     // Display method
  206.     public void Display() {
  207.         System.out.println("Size: " + String.format("%.3f", this.getSize()) + " cm.");
  208.         System.out.println("Size: " + String.format("%.3f", this.getSize()) + " cm.");
  209.     }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement