• Post Reply Bookmark Topic Watch Topic
  • New Topic

Educational maths idea  RSS feed

 
Ben Poland
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

In my head this seems like it would be quite a complex idea to write. So, here's the break down of what I want it to do:

1) Display a popup box. JOptionPane... I don't like the default look of it and I don't know how to play around with it. Any suggestions?
2) Welcome message, blah this and that (simple enough)
3) Have user press any key to start (simple enough)
4) Generate and display a random number (simple enough)

At this point in my head it starts to get somewhat more difficult:
5) If for example the random number is 678, ask the user what is the value of the first place holder. (Take input as a string rather than int and start using regex is what I'm thinking, but perhaps that wouldn't work)
6) Have the user enter the value as a string where the string has to match the numerical value, so the user would have to say the place holder value is the hundreds and in this case it's six hundred.
7) After the user enters the value, check to see it matches. If it does can move on to next challenge, if not ask user to try again (figure a simple while loop would take care of this part)
8) Congratulate for a correct answer and move on.

It's really from 5 - 7 where I think this might be fairly tricky. I could really use any suggestions you guys may have to make this work.

Thanks in advance for any help with this...

Ben
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're going to use JavaFX, you can use a TextInputDialog control:
 
Ben Poland
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey again,

So, here's what I've done so far...


So at this point essentially what I would like to be happening is that based on whatever random number is generated, say 12345, the user is then questioned on the value of 3 which I would like to be displayed in the same box that generated the number and for the user to be able to enter the value in the same box. It's this part and the next that presents the problem though.
1) The question would have to see the random number place (was thinking perhaps this could be done by creating an array?), this would be so that the question doesn't ask what is the value at place 5 if a 4 digit random number is generated. Due to the fact it's more than a single digit random number it would not be able to just ask "What's the value here?" as it needs to be specific.
2) User response would have to be able to be checked against the initial random number generated and either correct or incorrect answer.

I hope this makes sense and if so, please let me know your thoughts / suggestions on how I would go about doing this.

Thanks guys,

Ben
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Poland wrote:In my head this seems like it would be quite a complex idea to write. So, here's the break down of what I want it to do:

I think your problem is that you're mixing up design with implementation - ie, you're thinking about how you're going code this app while you're still trying to sort out what it does.

My advice: For the moment, forget about coding and concentrate on what you want the dialog to look like, and how it should flow. Specifically, you should be thinking about how it looks when things go smoothly, and what your "user" might do wrong (and what should happen in those cases).

And the first thing (IMO) is to come up with a proper name for this app: "Educational Maths" is incredibly vague, whereas your app is doing something quite specific; so how about something like "Number breakdown"?

Part of the art of programming is focusing on the problem at hand, and good naming can help you a lot there. A second one is concentrating on one task at a time, so finish your design before you start worrying about coding.

HIH

Winston
 
Ben Poland
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

Winston, I actually wrote up what I want it to do before I opened NetBeans I'm not sure if you'd have far more detail included here or not, but here's what I wrote:

App Name: Place Value
Display a Welcome Box
"Welcome to What's My Value"

Generate a random number between 1 - 1000000

Display the random number

Ask user in words, what is the value of a specific point in the number generated (123456: Position 3 = Three thousand)
Message:
"What is the third place value?"

If invalid data is supplied, generate a message, loop and prompt for a valid entry
Message:
"Invalid entry supplied. Please enter a valid value:"

If a valid entry is supplied, but the value is incorrect display a message and prompt to try again
Message:
"Sorry, that value was incorrect, try again, you'll get it!"

If a valid and correct entry is supplied generate a congratulations message and move on to the next challenge or give the user an option to quit program
Message:
"Congratulations! That was the correct answer!"
Message:
"Press Enter to try another number or press Q to quit"

If Q is pressed display a goodbye message is displayed
"Thank you for playing. Goodbye for now"

Otherwise start again


I've taken to doing something similar to this before I actually do any code now as per the suggestion before. If there are other details that you'd be more specific about, please let me know what they'd be as I will only help me moving forward.

Knute,

I'll have a play with that. Have pretty much no idea how that can be best utilised as yet, a LOT to learn eh? But I shall read up on this and learn how to use it and see if it will give me the control that I want from a popup box, although knowing all your previous advice it'll do exactly what I need it to and some

Thanks guys,

Ben

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Poland wrote:Winston, I actually wrote up what I want it to do before I opened NetBeans

Good - you're getting the idea.

However, since you're designing what looks like a GUI, I think I'd be writing diagrams of what I want each screen (or box) to look like, including any buttons or scrollbars, with maybe a bit of narrative describing the flow. They don't need to be works of art, but they should give you some "visual" clues.

Also, this description: "Ask user in words, what is the value of a specific point in the number generated (123456: Position 3 = Three thousand)" seems a bit vague.
What are you trying to test? That a user can count up to 3, or correctly translate the word "third"? Seems like an awful lot of code for such a basic test.
Is it always going to be 3? Do you specifically want to see the word "third" or "ninth" - ie, an English 'ordinal' - rather than "position 3"? If so, you need to translate a number to an ordinal word...for no good reason I can see (except perhaps as a mental exercise) because it doesn't add much value to your test.

Just because you're describing "what", not "how", doesn't mean you can afford to be vague, and there are still several things missing from your description.

HIH

Winston
 
Ben Poland
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However, since you're designing what looks like a GUI, I think I'd be writing diagrams of what I want each screen (or box) to look like, including any buttons or scrollbars, with maybe a bit of narrative describing the flow. They don't need to be works of art, but they should give you some "visual" clues.


Good call, Winston, I will do that with the GUI as I do have something fairly specific in mind.

Also, this description "Ask user in words, what is the value of a specific point in the number generated (123456: Position 3 = Three thousand)" seems a bit vague.
What are you trying to test? That a user can count up to 3, or correctly translate the word "third"? Seems like an awful lot of code for such a basic test.
Is it always going to be 3? Do you specifically want to see the word "third" or "ninth" - ie, an English 'ordinal' - rather than "position 3"? If so, you need to translate a number to an ordinal word...for no good reason I can see (except maybe for the mental exercise).


The idea is for this to be used to teach place values, so for a kid to see the number in digits and respond with words for the place values. The number would have to change everytime as would the place value. Perhaps a more elegant solution to this would be to highlight a number or have a pointer above it and ask what that value is? Does that make sense? :/

Point taken regarding "what" and "how".

Ben
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Poland wrote:The idea is for this to be used to teach place values, so for a kid to see the number in digits and respond with words for the place values.

OK, well that's not what I got from it. My assumption was that you are asking for the value in a particular random position, and their response would be a digit.

Like I say: precision is really important.

Winston
 
Ben Poland
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lol Good point and well made indeed

Ben
 
Ben Poland
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

I've been trying to find a way to highlight just one number in a randomly generated number, for example, if the random number 12345 was generated, is there a way to highlight just one of those numbers? Either by making that number bold, putting a mark over it, something like that.

Thanks guys,

Ben
 
Ben Poland
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey again,

Ok, so I am quite stuck once again

I'll try be as clear as I can about what I am trying to do. After a random number has been generated, break that number into parts, so if the number generated was 12345, separate those numbers into the place value to be used, so 1 is assigned a place value of 10000, 2 is assigned a place value of 1000 and so on. I'm really at a loss as to how I would do this.

Any pointers would be great.

Thanks guys,

Ben
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you probably want to do is split the number digit by digit from right to left, assigning the next power of 10:

5 * 10^0
4 * 10^1
3 * 10^2
etc.

So, to split the number into digits, can you think of a way to do this with the mod (%) operator and integer division?
 
Ben Poland
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Knute,

I believe this actually works, but I'm struggling to get it into an array... Also, it gets printed backwards from the original random number that gets generated.



I obviously need it to not be in reverse and I don't know how to now put this into an array which I think would be the best way to setup the actual place value questions. Hope that makes sense.

Thanks

Ben
 
Ben Poland
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thinking about it, I guess this would have to add the digits to an array on each loop? Can this be done?

Thanks,

Ben
 
Ben Poland
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey again,

Well, this works a LOT better, not reversed and separates each digit into an array.



Any advice / suggestions would be great please

Thanks guys,

Ben
 
Ben Poland
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops, here's the launcher also...



Thanks,

Ben
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Poland wrote:I obviously need it to not be in reverse and I don't know how to now put this into an array which I think would be the best way to setup the actual place value questions. Hope that makes sense.

There are several ways of doing this, but you might want to have a look at String.toCharArray().

After all, do your "digits" actually have to be numbers? You're going to be comparing them to something the user entered from the keyboard, don't forget,

Also: An ArrayList (or indeed any type of Java collection) should always be declared with a type, ie:
  ArrayList<SomeType> splitVal = new ArrayList<>();
not:
  ArrayList splitVal = new ArrayList();
and even better is to declare it as a List, viz:
  List<SomeType> splitVal = new ArrayList<>();
That way, if you decide later on that another type of List (eg, a LinkedList) is better, you only have to change your code in one place.

HIH

Winston
 
Ben Poland
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are several ways of doing this, but you might want to have a look at String.toCharArray().

After all, do your "digits" actually have to be numbers? You're going to be comparing them to something the user entered from the keyboard, don't forget,


Very true. I'll have a bash at the String.toCharArray.
What I'm thinking about mainly for now is how after the number has been generated and put into an array do I assign the place value? There are a number of things after that too, but one step at a time

Also: An ArrayList (or indeed any type of Java collection) should always be declared with a type, ie:
ArrayList<SomeType> splitVal = new ArrayList<>();
not:
ArrayList splitVal = new ArrayList();
and even better is to declare it as a List, viz:
List<SomeType> splitVal = new ArrayList<>();
That way, if you decide later on that another type of List (eg, a LinkedList) is better, you only have to change your code in one place.


Would you recommend declaring this local or instance? What is considered best practice? I tried both local and instance, but when at local the System.out in the run method did not have visibility of it. Sure I must be missing a little something there.

Thanks,

Ben
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You exchange using instance fields to local variables (usually a good thing) by doing something like this:

What would you have to do to separateVal to get this to work?
 
Ben Poland
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Knute,

Sorry reply took so long, my router messed up Was without connection for a while...


I added the ranVal variable as a parameter in the separateVal method, that sorted it I changed methods to private and removed the field so the variables are now local.

What is the advantage of using List<>name = ArrayList rather than ArrayList<> name = ArrayList? Aside having a only single piece of code to change(always an advantage) is there a functional difference?

So, next question, I figured the best way to make this work next is to have one of the digits printed out as bold or highlighted, otherwise I may get the same number twice and there won't be a frame of reference to which one the question refers to. Also with a single digit being formatted some way it saves having to mess about with a myriad of different questions. Hope that makes sense. And so the question is, how would I go about formatting a random digit and set the place value of the random generated number? Just a couple of pointers please guys and I'll hopefully get this sorted today

Thanks,

Ben
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Poland wrote:So, next question, I figured the best way to make this work next is to have one of the digits printed out as bold or highlighted, otherwise I may get the same number twice and there won't be a frame of reference to which one the question refers to.

Now I'm confused. I thought you were asking them to enter the digit in a certain position. Surely in that case it doesn't matter if you have duplicated digits or not?

Personally, I think that "digits" are a red herring here. It seems to me that you could just as easily show a string of random characters, and ask them which is the one at (say) position 4.

I think we (or you) have to get back to basics again: What is the point of this exercise?

HIH

Winston
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Poland wrote:What is the advantage of using List<>name = ArrayList rather than ArrayList<> name = ArrayList? Aside having a only single piece of code to change(always an advantage) is there a functional difference?

Well, ArrayList has ensureCapacity() and a trimToSize() methods; but other than that, very little. And the fact is that the main reason for using List (loose coupling) far outweighs any specific API considerations.

Winston
 
Ben Poland
Ranch Hand
Posts: 97
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey again, Winston

Yes, showing a string of random characters is the idea, just not good at wording things sometimes, so I'll break this down as best I can and try to make more sense than I usually do

1) Display random value: 12345
2) Assign place values to each location
3) Ask user the place value in random location

My thinking was that if the question is "What is the value at position 3?", the question itself would have to change each time as it can't ask that same question everytime.
So with that in mind, the question would also have to be applicable to the number of places in the random value, can't ask for place value 6 if the random number is only 12345.
Then the user response would have to be matched against the question.

Really what it boils down to is getting this to work in the simplest way. In theory it's very straight forward, but seems in practice not so much... I hope that makes more sense this time :/

Thanks,

Ben

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben Poland wrote:1) Display random value: 12345

Why not "abcde"?

Really what it boils down to is getting this to work in the simplest way. In theory it's very straight forward, but seems in practice not so much... I hope that makes more sense this time :/

And I suspect that's because you've been sidetracked by the issue of 'values' and "digits", rather than characters.

  • Create a random string, numeric or otherwise.
  • Display it.
  • Display a message with a random "position".
  • Check user's input against the character in that position.

  • HIH

    Winston
     
    Liutauras Vilda
    Sheriff
    Posts: 4917
    334
    BSD
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ben Poland wrote:can't ask for place value 6 if the random number is only 12345.
    You check the length of string "12345" and you generate random place value which is between 1 and the string length (including).
    Note: when you check if the user's guess is correct, that indices starts counting from 0.
     
    Ben Poland
    Ranch Hand
    Posts: 97
    2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hey guys,

    Ok, so I added:



    It gives me a random number from the string, also because the random number is in the question, that will randomise the question everytime so that's all good, but how do I set a place value to that and check user input against it? Using the 12345 as the random number again, 1 = 10000, 2 = 2000, 3 = 300 etc... What I need is for a kid that uses this to understand that a numbers in a certain position hold a certain value, it's the position itself that is important, not the number in that position. I figured the best way to check user input being correct or not is a while loop, userinput matches random position "congrats" otherwise prompt to guess again. I'm just really struggling to figure out or understand how I assign the place value itself at this point. Aside that I think all is ok? :/

    Thanks,

    Ben
     
    Knute Snortum
    Sheriff
    Posts: 4274
    127
    Chrome Eclipse IDE Java Postgres Database VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Knute Snortum wrote:What you probably want to do is split the number digit by digit from right to left, assigning the next power of 10:

    5 * 10^0
    4 * 10^1
    3 * 10^2
    etc.

    So, to split the number into digits, can you think of a way to do this with the mod (%) operator and integer division?

    One of the reasons I posted this is that it gets you thinking assigning the place value with the digit you extract. You figured out the way to split the number up arithmetically; now think about assigning a key and value in a Map to hold the placeholders.

    Thing to think about: what if a digit is in the number more than once?
     
    Ben Poland
    Ranch Hand
    Posts: 97
    2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hey Knute,

    Yes, the thing I'm trying to figure out now before even assigning the place value is how to NOT have a duplicate number in the string... If it's 6 numbers in length, I need it not to print out 463542 for example as if the question is "What is the place value of 4?" the user will have no clue which 4 is meant. I was looking for a way to format the output (have the number being questioned bolded or something like that), but that seems like a LOT of code and very messy for a single number to look different to the others. Finding a way to get a duplicate free value seems a better way.

    I could really use a clue on how to do this though. I've tried a bunch of different stuff, but nothing has worked with the Random number generator which is where this would have to be applied. I tried using the Math.random, but read that it can be unreliable.

    Any advice on how to go about doing this would be appreciated.

    Thanks guys,

    Ben

    P.S. And yes, I do still have to figure out how to assign place value And there I was thinking that this would be less of a challenge than it's turned out to be!
     
    Knute Snortum
    Sheriff
    Posts: 4274
    127
    Chrome Eclipse IDE Java Postgres Database VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ben Poland wrote:Yes, the thing I'm trying to figure out now before even assigning the place value is how to NOT have a duplicate number in the string... If it's 6 numbers in length, I need it not to print out 463542 for example as if the question is "What is the place value of 4?" the user will have no clue which 4 is meant.

    Well, you could just say "4 is in place 100000 and place 10."
    The Map could be Map<Integer, String> with the Integer being the digit and the String being the answer. If you find that a key already exists you could add to the String "and place nnn".

    Need more of a hint?
     
    Ben Poland
    Ranch Hand
    Posts: 97
    2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hey Knute,

    Well I've changed the code a fair bit in order to not get duplicates in the number:



    This just generates the number and then shuffles it. It ensures no duplication which was one of the things I wanted. Also this will prompt for a random number to question, that's another thing that I wanted, but the trade off is to ALWAYS have a 7 digit number which is certainly not ideal, but it's the only way I've been able to get a number without duplication. As you can see it's far less code too which is not a bad thing I think.

    I'm confused about assigning place value and checking user input against it though.

    I tried several different ways to get Random generating a number without duplicates, but no joy with any and without being able to format specific values in a random number (bold, italic or something like that) I pretty much figured I had to go this route.

    I'm sure there are several ways to get happening what I'm trying to do, but I'm stumped at how unfortunately. Either way, this is half way to getting it doing what I want it to, generates number, shuffles it to generate a random number, questions the user on a random place from the number. Would certainly rather be using Random, but seems that I can't do that. Please correct me if I'm wrong, sure I am. I'll continue looking for a way to set place value and check user input against it, so yes, a bit more of a hint would be nice please

    Thanks,

    Ben
     
    Knute Snortum
    Sheriff
    Posts: 4274
    127
    Chrome Eclipse IDE Java Postgres Database VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    To get a random digit without repeat the digit, try creating a String with all the digits you need ("0123456789" for instance), then get a random index into the string. If the index points to a digit, use it and replace the digit with something, like "x" ("012x456789" if you read a "3").
     
    Consider Paul's rocket mass heater.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!