Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discussion 3. Questions? Term test? Lectures? Labs?

Similar presentations


Presentation on theme: "Discussion 3. Questions? Term test? Lectures? Labs?"— Presentation transcript:

1 Discussion 3

2 Questions? Term test? Lectures? Labs?

3 Labs Indentation of different spaces are used Set the number of spaces of indentation in Dr Java (Edit ->Preference->Miscellaneous->Indent Level) Write the codes all in 1 block (difficult to read) Some lines did not indent properly Code are very similar with your friends (plagiarism?!)

4 Labs Did not follow the exact format specified in the lab assignment (e.g. Enter length: …) Did not follow the objectives / use syntax which you are not supposed to

5 Chapter 4 Section 4.11 Slides taken from the book

6 Problem Statement Problem statement: Write a loan calculator program that computes both monthly and total payments for a given loan amount, annual interest rate, and loan period.

7 Overall Plan Tasks: Get three input values: loanAmount, interestRate, and loanPeriod. Compute the monthly and total payments. Output the results.

8 Required Classes LoanCalculator Loan JOptionPanePrintStream inputcomputationoutput

9 Development Steps We will develop this program in five steps: 1. Start with the main class LoanCalculator. Define a temporary placeholder Loan class. 2. Implement the input routine to accept three input values. 3. Implement the output routine to display the results. 4. Implement the computation routine to compute the monthly and total payments. 5. Finalize the program.

10 Step 1 Design The methods of the LoanCalculator class MethodVisibilityPurpose startpublicStarts the loan calculation. Calls other methods computePaymentprivateGive three parameters, compute the monthly and total payments describeProgramprivateDisplays a short description of a program displayOutputprivateDisplays the output getInputprivateGets three input values

11 Step 1 Code Directory: Chapter4/Step1 Source Files: LoanCalculator.java Loan.java Directory: Chapter4/Step1 Source Files: LoanCalculator.java Loan.java Download from http://www.comp.nus.edu.sg/~cs1101x/sample_prog/Chapter4/

12 Step 1 Test In the testing phase, we run the program multiple times and verify that we get the following output inside describeProgram inside getInput inside computePayment inside displayOutput

13 Step 2 Design Design the input routines LoanCalculator will handle the user interaction of prompting and getting three input values LoanCalculator calls the setAmount, setRate and setPeriod of a Loan object.

14 Step 2 Code Directory: Chapter4/Step2 Source Files: LoanCalculator.java Loan.java Directory: Chapter4/Step2 Source Files: LoanCalculator.java Loan.java

15 Step 2 Test We run the program numerous times with different input values Check the correctness of input values by echo printing System.out.println("Loan Amount: $" + loan.getAmount()); System.out.println("Annual Interest Rate:" + loan.getRate() + "%"); System.out.println("Loan Period (years):" + loan.getPeriod());

16 Step 3 Design We will implement the displayOutput method. We will reuse the same design we adopted in Chapter 3 sample development.

17 Step 3 Code Directory: Chapter4/Step3 Source Files: LoanCalculator.java Loan.java Directory: Chapter4/Step3 Source Files: LoanCalculator.java Loan.java

18 Step 3 Test We run the program numerous times with different input values and check the output display format. Adjust the formatting as appropriate

19 Step 4 Design Two methods getMonthlyPayment and getTotalPayment are defined for the Loan class We will implement them so that they work independent of each other. It is considered a poor design if the clients must call getMonthlyPayment before calling getTotalPayment.

20 Step 4 Code Directory: Chapter4/Step4 Source Files: LoanCalculator.java Loan.java Directory: Chapter4/Step4 Source Files: LoanCalculator.java Loan.java

21 Step 4 Test We run the program numerous times with different types of input values and check the results.

22 Step 5: Finalize We will implement the describeProgram method We will format the monthly and total payments to two decimal places using DecimalFormat. Directory: Chapter4/Step5 Source Files (final version): LoanCalculator.java Loan.java

23 Things you must know for the test 16 September 2006, Saturday, 10am. There are 30 questions: 25 MCQs (multiple-choice questions), and 5 short-answer questions. Maximum score is 35 marks. Open book

24 Things you must know for the test JOptionPane showMessageDialog showInputDialog String substring length indexOf

25 Things you must know for the test Date SimpleDateFormat Type Casting (implicit? / explicit?) Wrapper Classes Integer.parseInt( “ 100 ” ) Double.parseDouble( “ 1.0 ” ) etc … DecimalFormat

26 Things you must know for the test System.out.println / System.out.print Scanner next() nextInt() etc … Math random max pow etc …

27 Things you must know for the test System.out.println / System.out.print Scanner next() nextInt() etc … Math random max pow etc … GregorianCalendar

28 Things you must know for the test Classes modifiers(e.g private, public … ) return type parameters Constructors accessors / mutators (getters / setters) actual parameters/formal parameters local variables

29 Things you must know for the test Operator precedence?

30 Things you must know for the test

31 if-then-else op= || && ! ? Operator == String.equals ? Switch break

32 What else you might want to do? Print API? Rest enough on Friday Read textbook, do exercises at the back Ask questions you are not sure in the forum etc … Get your 35 marks


Download ppt "Discussion 3. Questions? Term test? Lectures? Labs?"

Similar presentations


Ads by Google