//how to implement boolean onDry on the compiler and ask the question that the h
ID: 3571955 • Letter: #
Question
//how to implement boolean onDry on the compiler and ask the question that the hair is dry, so no hair drier needed import java.util.Scanner; public class Hairdry { //fields private boolean private String soft = "10 minutes" ; private String medium ="15 minutes"; private String hardhair ="20 minutes"; private int Hairtype =0; // Getter method public String getSoft() { return soft; } public String getMedium() { return medium; } public String getHardhair() { return hardhair; } public boolean getOnDry (){ return onDry; } //Setters public void setOnDry(boolean onDry) { this.onDry = onDry; } public void setSoft(String soft) { this.soft=soft; } public void setMedium(String medium) { this.medium=medium; } public void setHardhair(String hardhair) { this.hardhair=hardhair; } //constructor public Hairdry(String soft, String medium,String hardhair) { this.soft = soft; this.medium = medium; this.hardhair = hardhair; this.onDry = onDry; } public static void main (String [] args) { //object creation Hairdry hairdry = new Hairdry("soft hair","",""); Hairdry hairdryb = new Hairdry("medium hair","",""); Hairdry hairdryc = new Hairdry("hard hair","",""); int i = 0; boolean //prompt user to enter type of hairtype Scanner hairtype= new Scanner (System.in); System.out.println(); System.out.print("Enter hairtype from 1 to 10; with 1 being softest and 10 very hard hair:"); System.out.println (" "); i=hairtype.nextInt(); if(i<3) { hairdry.setSoft("Soft hair"); hairdry.getSoft(); System.out.print("Hair is soft, stay under dryer for 10 minutes:"); } else if(i<7) { System.out.println("Hair is medium, stay under dryer for 15 minutes."); hairdry.setMedium("Medium Hair"); hairdry.getMedium(); } else if(i<10) { hairdry.setHardhair("Hard hair"); hairdry.getHardhair(); System.out.println("Hair is hard, stay under dryer for 20 minutes."); } else if (boolean { System.out.println("your hair is dry, don't need to dry"); } }//main close }//class close
Explanation / Answer
import java.util.Scanner;
public class Hairdry {
// fields
private boolean> private String soft = "10 minutes";
private String medium = "15 minutes";
private String hardhair = "20 minutes";
private int Hairtype = 0;
// Getter method
public String getSoft() {
return soft;
}
public String getMedium() {
return medium;
}
public String getHardhair() {
return hardhair;
}
public boolean getOnDry() {
return onDry;
}
// Setters
public void setOnDry(boolean onDry) {
this.onDry = onDry;
}
public void setSoft(String soft) {
this.soft = soft;
}
public void setMedium(String medium) {
this.medium = medium;
}
public void setHardhair(String hardhair) {
this.hardhair = hardhair;
}
// constructor
public Hairdry(String soft, String
medium, String hardhair) {
this.soft = soft;
this.medium = medium;
this.hardhair =
hardhair;
this.onDry = onDry;
}
public static void main(String[] args) {
// object creation
Hairdry hairdry = new Hairdry("soft hair", "", "");
Hairdry hairdryb = new Hairdry("medium hair", "", "");
Hairdry hairdryc = new Hairdry("hard hair", "", "");
int i = 0;
boolean> // prompt user to enter type of hairtype
Scanner hairtype = new Scanner(System.in);
System.out.println();
System.out
.print("Enter hairtype from 1 to 10; with 1 being softest and 10 very hard hair:");
System.out.println("");
i = hairtype.nextInt();
System.out.println("Is the hair is dry?");
>
if (i < 3) {
hairdry.setSoft("Soft hair");
hairdry.getSoft();
System.out.print("Hair is soft, stay under dryer for 10 minutes:");
} else if (i < 7) {
System.out
.println("Hair is medium, stay under dryer for 15 minutes.");
hairdry.setMedium("Medium Hair");
hairdry.getMedium();
} else if (i < 10) {
hairdry.setHardhair("Hard hair");
hairdry.getHardhair();
System.out
.println("Hair is hard, stay under dryer for 20 minutes.");
}
if (onDry == true) {
System.out.println("your hair is dry, don't need to dry");
}
}
}
OUTPUT:
Enter hairtype from 1 to 10; with 1 being softest and 10 very hard hair:
6
Is the hair is dry?
true
Hair is medium, stay under dryer for 15 minutes.
your hair is dry, don't need to dry
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.