Objectives

Students will be able to:

  • assign data from the keyboard to a variable
  • understand how to catch an error
  • understand that a programmer sometimes has to tell the computer what kind of data is being assigned

Algorithms

An algorithm is a defined series of steps that must be followed in order to solve a problem.

Team Challenge

You have been hired by a popular restaurant chain to create a tip calculator program.

The program should allow the restaurant's customers to calculate the amount of tip to leave based on their bill amount and preferred tip percentage.

Requirements:

  1. Ask the user to enter the total bill amount.
  2. Ask the user to enter the tip percentage they would like to leave (e.g., 10, 15, 20).
  3. If valid inputs are provided, calculate and display the tip amount and the total amount (bill + tip)

Exception handling

  • The user enters a non-numeric value for the bill or tip percentage.
  • Can you find a way to make sure that users only enter positive numbers?

Allow the user to repeat the calculation or exit the program.

.

Submission

To gain credit, submit your .java file into Google Classroom.

Pseudocode

Often, program designers are amazing logical thinkers but are not experts on every programming language eg Java, Python, C++, C# etc

In big programming teams, program designers need to find a way to share a solution to a problem(s) with Java programmers, Python programmers, C++ programmers etc.

Pseudocode is often used. It looks like a programming language but it isn't really.

However, it can be understood by Java programmers who turn it into Java, Python programmers who turn it into Python, C++ programmers who turn it into....

Input and Exception Handling

 

Lucky Number Game

Enter a random number between 1 and 10. If you guess the lucky number, you win a prize!

Exception Handling

The above app demonstrates how a computer program has to handle user input.

What happens if you enter your name into the input box? Does the program crash? Or can it handle this awkward situation?

The program utilises exception (error) handling.

Click the starter activity to explore this concept in Java.

Starter Activity

Open a new file in your IDE and paste the stater code into it.

Watch the video and complete the worksheet

Tags

integratedsyntax development environment machine code translate type errorcompile