Albert Richards

Greenhorn
+ Follow
since Apr 28, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Albert Richards

Hi everyone,

I have a system where a user can order some predefined items. To do this, I have been using a switch statement, e.g:



However, once i've reached the end of the individual cases, I would like them to repeat, so the user could buy more than one item at once, and have this added to an array list. I think I have the array worked out, but the loop is proving problematic. I understand that the code below is one way I can do it, but I don't know how to increase the counter so the statement can loop properly.

Can anyone please help? Thanks



13 years ago
Hi my bad, I just realised. Thanks for that
13 years ago
Your right, not really no. I'm sorry I can't explain myself better.

Basically, I want one of those values to be returned, so it can be added to a cost which I have already calculated.
13 years ago
Hi everyone, thanks for all the help.

Could someone explain how I could pass the output of the case statement to another class which is using a scanner to get the input of either 1, 2 ,3 (e.g, the user inputs 1 into the scanner, then the value 0.10 is returned.)




I cannot seem to work it out how to get the scanner to take the value, then return the corresponding case return. I hope I have been clear enough, Thanks
13 years ago
Hi everyone,

I have already posted concerning switch statements. I was wondering if someone would be able to tell me how to implement and output a switch statement which I have in one class, say Numbers.



And then use these case inputs in another separate class, using a scanner to take the input and output the values of the case (e.g. input 1 into scanner --> 0.1 returned)

Also, once this has been done, would it be possible to refer back to this value, and use it to add to another number which had been inputted into the scanner?

Thanks again!!
13 years ago
Hi many thanks for the responses. I will look into what you have suggested.
13 years ago
Hello everyone, I am learning Java, and I would like to be able to do something.

I understand that switch statements allow for scenarios to be account for. I am trying to develop something in an object oriented manner, with abstract classes.

Could someone explain to me how I would be able to use a switch statement in the abstract class, then refer back to it at a later date.

I am looking for something that could do something like:

Case 1: return 10
case 2: return 20
case 3: return 30

then in another class return this value so I can add it to something else.

I hope I have been descriptive enough for someone to help me. Many thanks in advance!
13 years ago