Reply to another student's post. Modify the student's code by providing a modified approach to the class or suggestions for enhancement. * * * Import java.util.Scanner; public class Appliance { //Instance variables declared public int level; public char auto; //Method to assign values for humidity level and auto feature; taken from user input in main method public void setValues(int level, char auto) { this.level = level; this.auto = auto; } //Method to display results from user input public void displayStatus() { System.out.println("You have entered " + level + " for humidity"); System.out.println("You have entered " + auto + " for auto feature"); String setting = null; if (Character.toUpperCase(auto) == 'Y') { setting = "ON"; } else { setting = "OFF"; } System.out.println("\nThe humidity level is " + level + "%"); System.out.println("The auto feature is set to " + setting); } public static void main(String[] args) { //Create instance of class Appliance humidity = new Appliance(); Scanner scanint = new Scanner(System.in); Scanner scanchar = new Scanner(System.in); System.out.println("Hello user. This program will act as a way to set your humidistat"); //Prompt user for humidity and auto feature System.out.println("What percentage would you like to set the humidity to? Please enter an integer"); int hum = scanint.nextInt(); System.out.println("Would you like for the humidistat to turn on and off automatically? Enter 'Y' for yes, and any other key for no"); char feature = scanchar.next().charAt(0); //Call both methods humidity.setValues(hum, feature); System.out.println(); humidity.displayStatus(); scanint.close(); scanchar.close(); } }
Reply to another student's post. Modify the student's code by providing a modified approach to the class or suggestions for enhancement.
*
*
*
Import java.util.Scanner;
public class Appliance {
//Instance variables declared
public int level;
public char auto;
//Method to assign values for humidity level and auto feature; taken from user input in main method
public void setValues(int level, char auto) {
this.level = level;
this.auto = auto;
}
//Method to display results from user input
public void displayStatus() {
System.out.println("You have entered " + level + " for humidity");
System.out.println("You have entered " + auto + " for auto feature");
String setting = null;
if (Character.toUpperCase(auto) == 'Y') {
setting = "ON";
}
else {
setting = "OFF";
}
System.out.println("\nThe humidity level is " + level + "%");
System.out.println("The auto feature is set to " + setting);
}
public static void main(String[] args) {
//Create instance of class
Appliance humidity = new Appliance();
Scanner scanint = new Scanner(System.in);
Scanner scanchar = new Scanner(System.in);
System.out.println("Hello user. This program will act as a way to set your humidistat");
//Prompt user for humidity and auto feature
System.out.println("What percentage would you like to set the humidity to? Please enter an integer");
int hum = scanint.nextInt();
System.out.println("Would you like for the humidistat to turn on and off automatically? Enter 'Y' for yes, and any other key for no");
char feature = scanchar.next().charAt(0);
//Call both methods
humidity.setValues(hum, feature);
System.out.println();
humidity.displayStatus();
scanint.close();
scanchar.close();
}
}
Step by step
Solved in 2 steps