Solved

Switch strings

Posted on 2004-10-08
6
158 Views
Last Modified: 2012-05-05
Hi there

I'm trying to write a program where I can enter a day of the week, and feedback whether its falls during the week or weekend. I want to use a switch statement. Can you tell me how I convert the string so that I can use it in the switch?
0
Comment
Question by:moggiek
6 Comments
 
LVL 14

Accepted Solution

by:
Tommy Braas earned 25 total points
ID: 12263341
You can convert the day of the week to an integer and the use a switch statement. If you add all the names of the days of a week into a HashMap as keys and the corresponding day number as the value. You would however have to set that HashMap up in the first place.
0
 
LVL 9

Expert Comment

by:DrWarezz
ID: 12263378
Might I ask, why must it use a "switch" statement?
 -I hate to be nosy, but, it sounds like POSSIBLE homework. Which we're not alowed to help you with.

;) Just so you know
[r.D]
0
 
LVL 3

Expert Comment

by:CI-Ia0s
ID: 12263603
Hrmm... I thought the rule was no code-blocks (i.e. doing the program for them), but we can give general advice/code snippets? (http://www.experts-exchange.com/Programming/Programming_Languages/Java/help.jsp#hi130)

Meh, my only comment would be that you could also use if-statements:
if (dayInput.equals("Sunday")){dayInt = 1;}
else if (dayInput.equals("Monday")){dayInt = 2;}

etc.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 25 total points
ID: 12273074
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bunnyEars2 challenge 6 68
endX challenge 2 50
Unable to start eclipse ? 17 84
Checkbox and ListView in Android Layout 4 38
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now