Write a method called what Towear that receives a double number temp for current
ID: 3837984 • Letter: W
Question
Write a method called what Towear that receives a double number temp for current temperature, and a Boolean raincheck for current rain possibility and returns astring with a phrase based on the following conditions: If the temperature is less than or equal to 40 degrees, return the statement "wear a jacket" If the temperature is less than or equal to 40 degrees and raincheck is true, return the statement "Wear a jacket and bring umbrella" If the temperature is > 40 degrees 40 degrees 69 degrees, return statement wear light clothesExplanation / Answer
I ahve written this code in Java....
Based on the conditions you have provided...
ClothesDecider is the main class and it consists of the WhatToWear method which will return the results based on your inputs.
Comments are added in the Source code..
CODE :
package com;
import java.util.Scanner;
public class ClothesDecider {
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Hello User, Please enter today's Temperature. ");
//Variable to take the current temperature....
double temp = in.nextDouble();
System.out.println("Is it Raining Today ? Enter 'Y' for yes or 'N' for No ...");
//Variable to check whether it is raining
String rainChck = in.next();
// This method will check all the given conditions and return the results....
WhatToWear(temp,rainChck);
}
public static void WhatToWear(double temp,String rainChck)
{
try{
Boolean RC = rainChck.equalsIgnoreCase("Y") ? true : false ;
// Check all the required conditions one by one....You may add any other condition using else if...
if(temp <= 40 && RC == false)
{
System.out.println("Wear a Jacket today.!");
}
else if(temp<=40 && RC == true)
{
System.out.println("Wear a Jacket and bring an Umbrella..!");
}
else if(temp>40 && temp<=69 && RC == false)
{
System.out.println("Wear a light Jacket..");
}
else if(temp>40 && temp<=69 && RC ==true)
{
System.out.println("Dont forget your Umbrella...");
}
else if(temp>69 && RC == false)
{
System.out.println("Please wear light clothes today...");
}
else{
System.out.println("Please provide correct input parameters..");
}
}
catch(Exception e)
{
System.out.println("Oops Something went wrong...Please check all the Parameters and try again..!!");
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.