Page Contents
Enhancement -- Show a New Message


Code a New Message
Again open up code/text editor on Robo.java and then:

  • Go to our first message
  • Add a new message

Note: Don't forget the semi-colons ';' at the end of the lines
public void go()
{
	int n1, result;

	//PROGRAM STARTS HERE

	
1
showTextToUser("Hello End User, Good Day!");
2
showTextToUser("I am a Java program named 'Robo'");
Compile and Run with New Message
Again compile and run.

Our new message is shown 😊
Hello End User, Good Day!
I am a Java program named 'Robo'

Press any key to continue . . .


Enhancement -- Prompt For Number


Get A Number
  • Get a number from the end user
  • Re-display the number to the end user

Note: Don't forget the semi-colons ';' at the end of the lines

Variables

"n1" and "result" are variables (vars). We'll learn more about variables soon.
public void go()
{
	int n1, result;

	//PROGRAM STARTS HERE

	showTextToUser("Hello End User, Good Day!");

	showTextToUser("I am a Java program named 'Robo'");

	
1
n1 = getNumberFromUser("Please enter a number (integer): ");
2
showTextToUser("You entered: " + n1);
Compile and Run With Prompt
Again compile and run.


  • Our user prompt
  • Our re-display of the entered number
Hello End User, Good Day!
I am a Java program named 'Robo'

1
Please enter a number (integer): 10
2
You entered: 10 Press any key to continue . . .


Add Some Calculations


Code A Calculation
Add code to do a calculation. Our calculation doubles the entered number (variable "n1") and assigns the result to the variable named "result".
public void go()
{
	int n1, result;

	//PROGRAM STARTS HERE

	showTextToUser("Hello End User, Good Day!");

	showTextToUser("I am a Java program named 'Robo'");

	n1 = getNumberFromUser("Please enter a number (integer): ");

	showTextToUser("You entered: " + n1);

	result = n1 * 2;


Showing Result


Show The Result
Show the result to the user
public void go()
{
	int n1, result;

	//PROGRAM STARTS HERE

	showTextToUser("Hello End User, Good Day!");

	showTextToUser("I am a Java program named 'Robo'");

	n1 = getNumberFromUser("Please enter a number (integer): ");

	showTextToUser("You entered: " + n1);

	result = n1 * 2;

	showTextToUser("Your number doubled is: " + result);
Compile and Run With Calculation
Again compile and run.

Our program should now do:


  • Prompt user for a number (user entered 10 here)
  • Show the doubled number to the user (we calculated 20 here)
Hello End User, Good Day!
I am a Java program named 'Robo'

1
Please enter a number (integer): 10 You entered: 10
2
Your number doubled is: 20 I am done computing. I hope to see you again Press any key to continue . . .


Congragulations!


Congragulations! You have finished coding the example. 👍🏽