|
|
Java Student Project |
||
|
|||
Admission |
|||
|
|
|
||
| Ability Level: | Beginning | ||
|
|
|
||
| Estimated Time: | 40 minutes | ||
|
|
|
||
| Objectives: |
·
Learn to
use the System
class
to accept keyboard input · Be able to use the decision structure · Be able to control program flow by using the if and if…else statements · Learn how to nest if statements |
||
|
|
|
||
| Materials & Resources: |
|
||
|
|
|
||
| Overview: | Create a console application
project named Admission for a college's adminssions office.
Create variables to store a student's numeric high school grade
point average (for example, 3.2) and an admission test score.
Print the message "Accept" if the student has any of
the following:
|
||
|
|
|
||
| Instructions: |
Follow the instructions in the
overview. |
||
|
|
|
||
| Hints: | Some important
points to keep in mind in doing this project:
You can place and indent the if following an else, but a program with many nested if…else combinations soon grows very long and “deep,” and with indentations, later statements in the nest would move farther and farther to the right on the page. For easier-to-read code, Java programmers constantly place each else and it’s subsequent if on the same line. Remember that you reference character values using single quotation marks. Indentations in the if...else are not required, but is standard usage. You vertically align the keyword if the keyword else, and then indent the action statements that depend on the evaluation. You can code an if without an else, but it is illegal to code an else without an if. When you create a block, you do not have to place multiple statements within it. It is perfectly legal to block a single statement. An if statement ends with a semicolon. Making a decision involves choosing between two alternative courses of action based on some value within a program. You can use the if statement to make a decision based on a boolean expression that evaluates as true or false. If the boolean expression enclosed in parentheses within an if statement is true, then the subsequent statement or block will execute. Within an if or an else statement, you can code as many dependent statements as you need, including other if and else statements. Nested if statements are particularly useful when two conditions must be met before some action occurs. When you have a piece of code in which something can go wrong, you place the code in a try block. A try block consists of the following elements:
You must code at least one catch block immediately following a try block. Each catch block can "catch" one type of Exception. You create a catch block by typing the following elements:
Additionally, if a method throws an Exception that will be caught, you must use the keyword throws followed by an Exception type in the method header. The command line = in.readLine(); should be used to read in values. Now
use the following to hold the screen before you read in each
time: Then get a double value.
Remember to use new like this: Then use the following line to clear the input so you can read from the keyboard again. line = in.readLine(); Then read in the test score like you did the value.
|
||
|
|
|
||
| Extra: | |||