Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

#1
November 6th, 2012, 07:29 PM
 sabboy
Registered User

Join Date: Nov 2012
Posts: 1
Time spent in forums: 2 m 29 sec
Reputation Power: 0
Need help with boolean

The problem is,
As activity directory at Lake LazyDays Resort, it is your job to suggest appropriate activities to guests based on the weather:
temp >= 80: swimming
60 <= temp < 80: tennis
40 <= temp < 60: golf
temp < 40: skiing
1. Write a program that prompts the user for a temperature, then prints out the activity appropriate for that temperature. Use a cascading if, and be sure that your conditions are no more complex than necessary.
2. Modify your program so that if the temperature is greater than 95 or less than 20, it prints "Visit our shops!". (Hint: Use a boolean operator in your condition.) For other temperatures print the activity as before.

How would i do the boolean because i have no idea how they work this is the current code i have,

Code:
```import java.util.*;

public class Charge
{
public static void main(String [] args)
{
double temp = 0;
System.out.println("What is the temperature:");
Scanner scan  = new Scanner(System.in);
temp = scan.nextDouble();
if (temp >= 80.0)
{
System.out.println("Swimming");
}
else if (temp >= 60.0 && temp <= 80.0)
{
System.out.println("Tennis");
}
else if (temp >= 40.0 && temp <= 60.0)
{
System.out.println("Golf");
}
else if (temp < 40)
{
System.out.println("Skiing");
}
else if (temp >= 95 || temp <= 20)
{
}
}
}```

#2
November 7th, 2012, 01:30 PM
 NormR
Contributing User

Join Date: Aug 2010
Location: SW Missouri
Posts: 2,956
Time spent in forums: 1 Week 6 Days 2 h 56 m 11 sec
Reputation Power: 345
Quote:
 i have no idea how they work

The boolean operators: AND (&&), or (||) and ! are used to combine boolean expressions to return a single boolean value:
For example:
(a>b) && (c<d) would return true if a is greater than b AND c is greater than d
(a>b) || (c<d) would return true if a is greater than b OR c is greater than d
!(a>b) would return true if a is NOT greater than b (ie less or equal)

Please edit your code and properly format it to show logic nesting levels. Statements within {} should be indented.

Can you explain what happens when you execute your program?
Post the contents of the console that shows what you enter and what it prints out and explain what is wrong.

In windows To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

Last edited by NormR : November 7th, 2012 at 01:34 PM.

 Viewing: Dev Shed Forums > Programming Languages > Java Help > Need help with boolean