Discussion 3 Questions Term test Lectures Labs Labs
Discussion 3
Questions? Term test? Lectures? Labs?
Labs n Indentation of different spaces are used n n 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? !)
Labs n n 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
Chapter 4 Section 4. 11 Slides taken from the book
Problem Statement n 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.
Overall Plan n Tasks: n n n Get three input values: loan. Amount, interest. Rate, and loan. Period. Compute the monthly and total payments. Output the results.
Required Classes Loan. Calculator JOption. Pane Loan input computation Print. Stream output
Development Steps n We will develop this program in five steps: 1. 2. 3. 4. 5. Start with the main class Loan. Calculator. Define a temporary placeholder Loan class. Implement the input routine to accept three input values. Implement the output routine to display the results. Implement the computation routine to compute the monthly and total payments. Finalize the program.
Step 1 Design n The methods of the Loan. Calculator class Method Visibility Purpose start public Starts the loan calculation. Calls other methods compute. Payment private Give three parameters, compute the monthly and total payments describe. Program private Displays a short description of a program display. Output private Displays the output get. Input private Gets three input values
Step 1 Code Download from http: //www. comp. nus. edu. sg/~cs 1101 x/sample_prog/Chapter 4/ Directory: Chapter 4/Step 1 Source Files: Loan. Calculator. java Loan. java
Step 1 Test n In the testing phase, we run the program multiple times and verify that we get the following output inside describe. Program get. Input compute. Payment display. Output
Step 2 Design n Design the input routines n n Loan. Calculator will handle the user interaction of prompting and getting three input values Loan. Calculator calls the set. Amount, set. Rate and set. Period of a Loan object.
Step 2 Code Directory: Chapter 4/Step 2 Source Files: Loan. Calculator. java Loan. java
Step 2 Test n n 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. get. Amount()); System. out. println("Annual Interest Rate: " + loan. get. Rate() + "%"); System. out. println("Loan Period (years): " + loan. get. Period());
Step 3 Design n n We will implement the display. Output method. We will reuse the same design we adopted in Chapter 3 sample development.
Step 3 Code Directory: Chapter 4/Step 3 Source Files: Loan. Calculator. java Loan. java
Step 3 Test n n We run the program numerous times with different input values and check the output display format. Adjust the formatting as appropriate
Step 4 Design n Two methods get. Monthly. Payment and get. Total. Payment 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 get. Monthly. Payment before calling get. Total. Payment.
Step 4 Code Directory: Chapter 4/Step 4 Source Files: Loan. Calculator. java Loan. java
Step 4 Test n We run the program numerous times with different types of input values and check the results.
Step 5: Finalize n n We will implement the describe. Program method We will format the monthly and total payments to two decimal places using Decimal. Format. Directory: Chapter 4/Step 5 Source Files (final version): Loan. Calculator. java Loan. java
Things you must know for the test n n n 16 September 2006, Saturday, 10 am. There are 30 questions: 25 MCQs (multiple-choice questions), and 5 short -answer questions. Maximum score is 35 marks. Open book
Things you must know for the test n JOption. Pane n n n show. Message. Dialog show. Input. Dialog String n n n substring length index. Of
Things you must know for the test n n Date Simple. Date. Format Type Casting (implicit? / explicit? ) Wrapper Classes n n n Integer. parse. Int(“ 100”) Double. parse. Double(“ 1. 0”) etc… Decimal. Format
Things you must know for the test n n System. out. println / System. out. print Scanner n next() next. Int() etc… Math n n n random max pow etc…
Things you must know for the test n n System. out. println / System. out. print Scanner n n n Math n n next() next. Int() etc… random max pow etc… Gregorian. Calendar
Things you must know for the test n Classes n n n n modifiers(e. g private, public …) return type parameters Constructors accessors / mutators (getters / setters) actual parameters/formal parameters local variables
Things you must know for the test n Operator precedence?
Things you must know for the test
Things you must know for the test n n n n if-then-else op= || && ! ? Operator == String. equals ? Switch break
What else you might want to do? n n n 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
- Slides: 32