reset password
Author Message
wcwir
Posts: 75
Posted 17:29 Mar 20, 2019 |

Post then in this thread.

dliang
Posts: 35
Posted 22:45 Mar 22, 2019 |

Does anyone have any idea, how to print out the output twice? For what I did in the Names Generator 1, which I isolated the first uppercase letter and used the for loop for the lowercase letter. It works great, but my output can only appear once. In NameGenerator1A, the requirement asking for the "name" must appear in the output at least twice.

Last edited by dliang at 22:46 Mar 22, 2019.
dliang
Posts: 35
Posted 22:56 Mar 22, 2019 |
wcwir wrote:

Post then in this thread.

Ms.Cwir

I wonder can we post our program file here for the discussion? It will be helpful to study for the midterm, maybe just this time? Or we can go over these questions in the class. 

wcwir
Posts: 75
Posted 23:13 Mar 22, 2019 |

Hi Sam -- it is OK for you to post parts of it, but it is not OK for others to copy it.

As for your other question, if you want to print out the randomly generated character sequence twice, you have to store it somehow. And as it happens, we have a data type in Java made exactly for storing character sequences!

wcwir
Posts: 75
Posted 23:29 Mar 22, 2019 |

I just looked through the textbook, and this isn't covered very well -- but basically you can take separate characters and build a String out of them.

You have to be careful though:

Try this: 

String s = 'a' + 'b';

and it won't work -- that is because Java will think that you are using the the two char literals 'a' and 'b' as their numerical equivalents, and it will think you are trying to add them.

If you want to concatenate them instead, add them to an empty String:

String s = '"" + 'a' + 'b';

That will work, and now you have the String "ab" which you can reuse as you please.

wcwir
Posts: 75
Posted 20:15 Mar 29, 2019 |

To solve the FiveDice2 program, you have to store the information about what numbers were generated by the dice throws somehow -- not in the String. (Since that is a trick you already mastered in the NameGenerator1a program, I want you to learn something new.) How to do this?

You can look at this example program: https://csns.calstatela.edu/download?fileId=6731548 for inspiration.

HINT: in the number 94853, how much does the digit '9' contribute to the value? what about '4'? what about '8'? In general, how is the position of a digit in a decimal number related to the value it contributes to that number?

 

dliang
Posts: 35
Posted 22:59 Apr 20, 2019 |
wcwir wrote:

To solve the FiveDice2 program, you have to store the information about what numbers were generated by the dice throws somehow -- not in the String. (Since that is a trick you already mastered in the NameGenerator1a program, I want you to learn something new.) How to do this?

You can look at this example program: https://csns.calstatela.edu/download?fileId=6731548 for inspiration.

HINT: in the number 94853, how much does the digit '9' contribute to the value? what about '4'? what about '8'? In general, how is the position of a digit in a decimal number related to the value it contributes to that number?

Professor Wcwir

     Is we going to have a quiz at Monday for the Array Chapter?

 

wcwir
Posts: 75
Posted 23:09 Apr 20, 2019 |

Yes, there will be a quiz on Monday (or Tuesday, for my Tu-Th section). It will cover sections 7.1 through 7.4.