Sei sulla pagina 1di 3

IS3230 Sem A, 2016/17

IS3230 Tutorial Week 02 Solution


Exercise 1: --- Team Project Introduction && Team Formation
Please download the project instruction from Canvas:
https://canvas.cityu.edu.hk/login
Introduce yourself to your classmates around you. The course project and some
tutorial exercises will need a team to work on, so please form team (Maximum 5
students) to enable collaborative learning and support each other in the group
project and tutorial exercises. Submit your team information using Canvas.

Exercise 2: --- Verify Your Setup for Java Environment


1. Open Notepad++ and type in the following

2. Save it as MyFirstProgram.java
3. Open a Command Prompt
4. Change to the directory to where youve saved the above file (refer to
T2_slides.ppt for how to change directories)
5. Type in javac HelloWorld.java, followed by Enter
6. Type in java HelloWorld, followed by Enter

Questions: was your java code case sensitive? ~~ Yes


Exercise 3: --- Practice comments and output
1. Open Notepad++ and type in the following

CityU IS Dept

1 | Page

IS3230 Sem A, 2016/17

2. Save your file as Week2Ex3.java


3. Run your java code using javac Week2Ex3.java
4. Type in java Week2Ex3 and see what you get in console

Questions: 1) what is the difference you see between System.out.print and


System.out.println?
System.out.print print on the same line while
System.out.println terminate the current line and
whatever later will be printed on a new line
2) What doesn \n do?
Start a new line
3) How did you add different values together?
Using +
Exercise 4: --- Algorithm Workbench
Write pseudo code algorithms for the programs described as follows:
1. Available Credit
A program that calculate a customers available credit should ask the
user for the following:
The customers maximum amount of credit
The amount of credit used by the customer
Once these items have been entered, the program should calculate
and display the customers available credit. You can calculate available
credit by subtracting the amount of credit used from the maximum
amount of credit.
Display "What is the customer's maximum amount of credit?"
Input maxCredit.
CityU IS Dept
2 | Page

IS3230 Sem A, 2016/17

2. Sales

Display "What is the amount of credit used by the customer?"


Input creditUsed.
availableCredit = maxCredit creditUsed.
Display availableCredit.
Tax
A program that calculates the total of a retail sale should ask the user
for the following:
The retail price of the item being purchased
The sale tax rate
Once these items have been entered, the program should calculate
and display the following:
The sales tax for the purchase
The total of the sale
Display "What is the retail price of the item?"
Input retailPrice.
Display "What is the sales tax rate?"
Input taxRate.
salesTax = retailPrice * taxRate.
total = retailPrice + salesTax.
Display salesTax.
Display total.

3. Account Balance
A program that calculates the current balance in a savings account
must ask the user for the following:
The starting balance
The total dollar amount of deposits made
The total dollar amount of withdrawals made
The monthly interest rate
Once the program calculates the current balance, it should be
displayed on the screen.
Display "What is the account's starting balance?"
Input startingBalance.
Display "What is the total amount of the deposits made?"
Input deposits.
Display "What is the total amount of the withdrawals made?"
Input withdrawals.
Display "What is the monthly interest rate?"
Input interestRate.
balance = startingBalance + deposits withdrawals.
interest = balance * interestRate.
balance = balance + interest.
Display balance.
Exercise 5: --- Submit your work [Individual]
Please submit the answers (in MS Word format) of Exercise 3 and 4.3 to Canvas
under Tutorial WK2 Submission Link. (Deadline: 11/09/2016, 23:59, no late
submission will be accepted)
End of Tutorial 2
CityU IS Dept

3 | Page

Potrebbero piacerti anche