Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 6th, 2012, 07:29 PM
sabboy sabboy is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 sabboy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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)
{
System.out.println("Visit our shops!");
}
}
}

Reply With Quote
  #2  
Old November 7th, 2012, 01:30 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,956 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Need help with boolean

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap