• Post Reply Bookmark Topic Watch Topic
  • New Topic

How many Sentinel values can be in one Java program?  RSS feed

 
John Wolfe
Greenhorn
Posts: 2
Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a program that I'm trying to get different types of input from a user. The inputs will be alphabetic for the most part, but I need to be able to accept numeric values, until a sentinel is entered for each entry. Is this possible? Can I have 3, 4 (or more), Sentinel values in one program and have them work together?

The first method, "game_Time" uses a "q" as the sentinel, and this works. When I enter a "q", the program stops. But I want to be able to go to the second method, and later a third, looping through each method until I enter "q" in the game_Time method. As it is now, I can force the method game_Time to change to Color_Guess, but this is not an ideal solution.

I would greatly appreciate anyone looking at what I have posted, and advising me of any errors in logic.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

I spot one bug in your code, in line 48:

You are assigning true to Name_valid there. Instead of =, you should have used ==:

Or, better yet, the whole == true isn't necessary at all, since Name_valid is already a boolean:

 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Why are all your methods static? Use of static without a good reason suggests you are not writing object‑oriented programming.
Another minor error: despite you see in many books, you should not use \n or\r unless somebody has told you they require a particular character output. If you look here with ctrl‑F \n you will find an example which emits line ends correctly.
The number of possible sentinel values is equal to the length of a piece of string You will have to work out how to get them to work together; we don't know what you actually want.
When you are more experienced, you will learn how to put your sentinel values into a set and check whether the set contains a particular value. If you choose the right sort of set, you will not get slow execution.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should not use \n or\r unless somebody has told you they require a particular character output. If you look here with ctrl‑F \n you will find an example which emits line ends correctly.

My guess would be that for a console/terminal like in this code, the issue is moot.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did say minor error.
 
John Wolfe
Greenhorn
Posts: 2
Java Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To everyone who responded, THANK YOU!!!

You all impressed me with your ability to review my code and find my errors and assist me with my question.

I only hope I may become half as skilled as you all.

Thank you again
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!