Activity Class:
Develop a class that “suggests” an activity based upon the temperature. The temperature should be maintained via a private variable with public accessor and mutator methods. Two constructors are needed. The default constructor should set the temperature to 0. A second constructor should be created to accept an initial temperature value. An additional method named suggestion should return a String containing the “suggested” activity. When the temperature is above 85, the method should suggest swimming. When between 70 and 84, the method should suggest tennis. When the temperature given is between 60 and 69, hiking is suggested. When the temperature is below 60, the method should suggest board games.
Client Application:
Create a Java client application to test your class. The client should obtain a temperature from the user and use the class to determine the activity to report back to the user.
Activity class code
/**
* Java Chatbot Service class
* @author blake
* 2/26/2012
*/
public class Activity
{
private int temperature;
public Activity(int newtemperature)
{
temperature = newtemperature;
}
public String getActivity()
{
String a = "board games";
if (temperature > 85)
{
a = "Suggests Swimming";
return a;
}
if (84 < temperature && temperature > 70)
{
a = "Suggests Playing Tennis";
return a;
}
if (69 < temperature && temperature > 60)
{
a = "Suggests Hiking";
return a;
}
if (temperature < 60)
{
a = "Suggests Playing Board Game";
return a;
}
return a;
}
}
Activity Client Code
/**
* Java Chatbot Service class
* @author Blake
* 2/26/2012
*/
import java.util.Scanner;
public class ActivityClient
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Temperature of weather today: ");
int temperature = in.nextInt();
Activity act = new Activity(temperature);
System.out.println(act.getActivity());
}
}
Okay here’s the major issue I am having, it’s with the boolean expressions.
When ever I compile and run the programs it suggests activity that I don’t want.
Answer that worked
temperature today: 90
suggest swimming
temperature today: 58
suggest playing board games
THOSE TWO work
but whenever I put in
temperature today: 77
suggest hiking (when it should be Tennis)
temperature today: 66
suggest board games (when it should be Hiking)
So I was wondering what am I doing wrong with the methods for Hiking and Tennis.
Your condition are not really good. Look at :
Means temperature is more than 69 and temperature is more than 60.
I think you meant :