Instructor: Phill Conrad
TAs: Esra Kucukoguz, Yiming Li, Murali Yeleswarapu
Primary TA for this lab: Esra Kucukoguz
Starting this week, our plan is for Esra and Yiming to alternate weeks.
Murali will provide additional help as needed, and help with grading.
This week, we want to work with a Java class that comes from your textbook, from Chapter 3, and add some code to it.
You may work with one other student on this project, or you may work alone. If you work with another student, please list his/her name in the comments. Each of you must still turn in your work independently, however, for an individual grade.
turnin command, not to mention details such as editing files, and using the javac and java commands.Take a look at these two classes. In a later step, you'll be asked to make some modifications to each of them, so it is worth getting to know them a bit.
The first class, BankAccount provides two constructors for a bank account: one that creates an account object with a zero balance, and another that creates an account object with whatever balance is passed in as a parameter. There are then three methods for depositing money, withdrawing money, and checking the balance.
The second class, BankAccountTester, consists only of a main method that we can run to test the class. In lecture we've been looking at using the JUnit features built into BlueJ to do testing—and we'll get to that in lab next week. For now, we're doing something a bit more simple. BankAccountTester just has simple main method that uses the capabilities of the BankAccount class and then prints the result, along with what we expect the result to be.
Here's a link to the Javadoc for this class, which explains the methods it provides:
http://www.cs.ucsb.edu/~pconrad/cs10/09S/labs/lab01/BankAccountProject/doc
When you've spent a few moments looking over this code, continue on with the next steps.
~/cs10/lab01/cs/students/jsmith cd cs10mkdir lab01cd lab01This changes your directory to the cs10 directory, creates a new lab01 directory inside it, and then puts you in that directory.
~/cs10/lab01 directory. Save them with their original names: either BankAccount.java, or BankAccountTester.java. You can do this by one of several techniques: ~/cs10/lab01 directory, and save it with the name it originally had~/cs10/lab01 directoryBankAccount.java or BankAccountTester.java javac *.javaBankAccount.class and BankAccountTester.class in the listing, along with BankAccount.java and BankAccountTester.java.pwd and ls commands to see where you are, and what you have, and if necessary use the cd command to navigate to where you should be.-bash-3.2$ javac *.java
javac: file not found: *.java
Usage: javac <options> <source files>
use -help for a list of possible options
-bash-3.2$
BankAccount.class and BankAccountTester.class in your directory, you are ready to try running the test program. To do that we type:java BankAccountTester.java or .class after BankAccountTester when using the java command. The java command invokes the Java Virtual Machine (JVM) and says that we want to load the BankAccountTester class, look for its main(String [] args) method, and start running the code in that method.-bash-3.2$ java BankAccountTester
1500.0
Expected: 1500
-bash-3.2$ System.out.println(harrysChecking.getBalance());
System.out.println("Expected: 1500");
java BankAccount at the command line. BankAccount.java code, or is this something normal and expected?BankAccount.java file, use a comment like this one (replace Sally Coder with your name):
/**
A bank account has a balance that can be changed by
deposits and withdrawals.
@author Sally Coder
@version cs10, lab01, Spring 2009
*/
If you work with another programmer, indicate that this way:
/**
A bank account has a balance that can be changed by
deposits and withdrawals.
@author Sally Coder, working with Marge Inovera
@version cs10, lab01, Spring 2009
*/
Use a similar format to change the comments in the BankAccountTester.java file. We'll use this format throughout the course, so I won't explain it in this much detail every time—I may just refer back to this lab.
public void addInterest( double rate)BankAccount class that adds interest at the given rate. For example, after the statements: BankAccount momsSavings = new BankAccount( 1000);
momsSavings. addInterest( 10); // 10% interest
momsSavings should be $1,100. Also supply a BankAccountTester class that prints the actual and expected balance. addInterest that simply does nothing, i.e.public void addInterest( double rate){
// do nothing for now———this is a stub! @@@
}BankAccountTester class so that its main method makes the calls supplied above, prints out the new balance, and then prints out a message saying what the new balance was expected to be.addInterest() method—i.e. fill in the stub—and then test again. You should see that the program now works correctly. If so, you are ready for the turnin step.cd .. to move into the parent directory, i.e. the ~/cs10 directory. ls command to verify that the lab01 directory shows up in your listingturnin lab01@cs10 lab01Grading: This lab is worth 100 pts, distributed as follows. Partial credit may be awarded for each step at the discretion of the TA/Instructor.
.java files named BankAccount.java and BankAccountTester.java in your submission that contain code that can be compiled without error.BankAccountTester.java in a tests the addInterest() method correctly. BankAccount.java file in a way that implements the addInterest() method correctly.Due Date: You should do your best to complete this within the assigned lab time 04/09 or 04/10. If that is not possible, then you should complete the assignment and execute the turnin command no later than 4pm 04/17. This gives you one full week to seek help during office hours from both the instructor and the TAs, plus one additional lab period to ask the TAs for additional help.
Submissions turned in after that time are subject to receiving zero credit.
End of lab01