6 caculate

icon picker

input process and output a result that involves working with text

program requirement

New members in an organisation they will usually be given an email address to use with the company. Often the email address will combine the person’s name and also the name of the organisation.
This program should ask the user to enter and store text values for their name and the name of the company. The program should then produce the email address by adding the joining the text values together with the @ symbol and the domain of the company as shown in the example. This email address should be displayed for the user.

learning point

concatenation is the proper technical term for creating a new text value by joining 2 or more String values
A String expression is a list of String values or String variables and the concatenation operator
in java the concatenation operator for Strings is +
the same symbol is used for arithmetic addition of numbers
the program evaluates or “works out” the String value or result of the expression
the String value that is produced by the evaluation is then assigned to a String variable
checking that the output is very important now and you will need to know what the expected output will be to ensure the program has the correct result

expected output

What is your surname?: duke
What is your company?: amazon
You're email is duke@amazon.com
understanding the output
the user has entered two text values which the program has used to produce a new combined text value including both original text values and other text characters
the new combined text value is displayed for the user to read

introducing the code

1 System.out.print("What is your surname? ");
2 surname = keyboard.nextLine();
3 System.out.print("What is your company? ");
4 company = keyboard.nextLine();
5 email = surname + "@" + company;
6 System.out.println("You're email is " + email + ".com");
understanding the code
line 5 includes the expression surname + "@" + company which the program evaluates to produce a result
the current content of the two variables (input by the user) and a String value are concatenated together
+ is the concatenation operator (since it is placed between String values)
the result of evaluating the String expression is a String value
the value that results from the addition is assigned to the variable email
it is important that email is also a String variable since it has to store the result which is a String

the program code



Read the code and assume the user enters the name ada who has started work for a company called babbage.
Can you anticipate what would appear on the console when the program is run?
sometimes this is called the expected output

go ahead and run the program, enter the example values used above, then run the program again and enter your own test values
look at the results displayed by the program, these are called the actual output
check that the expected output is the same as the actual output

what happen if you changes the calculation to this?
email = company + "@" + surname;

Here is the full dialog that the program should create with the user. Read, copy and re-use the code you already have for entering the email address.
what new variables will you need?
what will the calculation look like, what operator will you need?
What is your surname?: duke
What is your company?: amazon
You're email is
What is your charity organisation name?: lovelace
The company website URL is https://www.lovelace.org


Lots of online platforms use some kind of identifier. For example #hashtag or @twitter_handle
Can you come up with another online id generator, perhaps a hashtag maker, a twitter handle maker? The user should be able to enter a name of a phrase and the app should produce and display the online identifier by combining the input with some other characters
Think carefully about how you would produce the id and what types of data and what variables would be involved. What would the prompt be?

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
) instead.