Business Programming

Course announcements for INFS1609 and INFS2609

Business Programming random header image

Tutorial – Week 12

Posted by on October 9th, 2011 · Labs

This a catch up week. Continue with the exercises from last week to complete your understanding of GUI programming.

Assignment 3 update

Posted by on October 3rd, 2011 · Assignments

Check the assignment specification for a clarification of how to handle the interest rate period. Also, download a new version of the skeleton. There was an error in RunTransactions, where a withdrawal was incorrectly given as a positive number when it should be negative.

Also note that the credit limit is passed as positive number but it as actually the lower bound on credit card transactions. How will you deal with that?

Tutorial – Week 11

Posted by on October 3rd, 2011 · Labs

Graphical User Interfaces

Download the zip file containing all the examples from chapter 11 of the text book. When you unzip the file, you will find several folder containing successively more complex examples of  GUI building.

Start with the simplest imageviewer0-1 and work your way through the code line by line making sure that you understand each step. If there is a class of method that you are not familiar with, look it up in the Java API documentation. If you still can’t work it out, ask you tutor. Try running the project. Look at the output and, if you are not sure how the program works, try using the debugger to trace the execution of the program.

Once you’ve understood the first program, work you way through the others. The later ones are quite complex, so don’t be too concerned if you don’t understand everything in them. You won’t get through all of them in this tutorial.

Tutorial – Week 10

Posted by on September 25th, 2011 · Labs

The following exercises are taken from chapter 10 of the textbook. Exercises 1 – 7 explore the simulation so that you become familiar with how it works and with the Java code. The most important exercises to complete for this week are exercises 8 and 9, so don’t spend too long on the earlier ones so that you can get onto creating your own class hierarchy.

Exercise 1 Open the foxes-and-rabbits-v1 project. Create a Simulator object using the constructor without parameters and you should see the initial state of the simulation. The more numerous rectangles represent the rabbits. Does the number of foxes change if you call the simulateOneStep just once?

Exercise 2 Does the number of foxes change on every step? What natural processes do you think we are modelling that cause the number of foxes to increase or decrease?

Exercise 3 Call the simulate method to run the simulation continuously for a significant number of steps, say 50 or 100. Do the numbers of foxes ad rabbits increase or decrease? You can use the runLongSimulation to see what happens over a long time.

Exercise 4 Use the reset method to create a new starting state and try running the simulation again. Is the simulation identical? If not, are there any similarities between runs?

Exercise 5 After having run the simulation for a while, reset it and also call the static reset method in the Randomizer class. Now run the first few steps again and you should see the original simulation repeated. Take a look at the code of the Randomizer class to see if you can work out why this might be. You might need to look at the API for the java.util. Random class to help you with this.

Exercise 6 Check that setting the userShared field on Randomizer to false breaks the repeatability of the simulations. Be sure to restore it to true afterwards because repeatability will be an important element in later testing.

Exercise 7 Experiment with different combinations of settings (breeding age, maximum age, breeding probability, litter size, etc) for foxes and rabbits. Do species always disappear completely in some configurations? Are there configurations that are stable?

Exercise 8 Identify the similarities and differences between the Fox and Rabbit classes. Make separate lists of the fields, methods and constructors and distinguish between the class variables (static fields) and instance variables.

Exercise 9 Create the Animal superclass in your version of the project. Ensure that the simulation works in a similar manner as before. You should be able to check this by having old and new versions of the project open side-by-side, making identical calls on Simulator objects in both, expecting identical outcomes.

 

Assignment 3 – UPDATE (04/10/2011)

Posted by on September 22nd, 2011 · Assignments

Due: 23:59:50 Sunday 9 October 2011

ChangeLog

  • Revision 04/10/2011: corrected error in RunTransactions
  • Revision 04/10/2011: Clarified use of  period.
  • Added submission instructions

Task

This assignment continues the theme of the earlier assignments, building a simple bank transaction system. In this program, you will use inheritance to create different kinds of accounts and transactions.

A skeleton for the program is provided here. It contains all the same classes as in assignment 2. Your task is to create two new subclasses of Account. One class, SavingsAccount, represents an interest bearing account. Periodically, a method in the SavingsAccount object will be called to calculate the interest for the period and generate a transaction to pay the account the account the interest. The interest formula is:

balance * interestRate/period

where interestRate is a number between 0 and 1 representing the annual interest rate (e.g. 4% interest = 0.04) and period is how often the interest is calculated (e.g. period = 12 means that the interest is calculated monthly).

A second subclass of account is CreditCard. Whereas a savings account is never allowed to have a negative balance, a CreditCard account may go negative. If the balance is negative, interest is calculated but this time, it is charged to the account. That is, the interest amount is subtracted from the balance.

Credit cards usually have a credit limit. That is, a customer cannot use the credit card if the balance has exceeded the credit limit. So transactions generated by the customer must be disallowed if the credit limit is exceeded. However, transactions generated by the bank when it charges interest can exceed the credit limit. That is, the bank can keep making your balance more and more negative but you can’t!

You should also create two subclasses of Transaction called, BankTransaction and CustomerTransaction to allow your program to distinguish between transactions that can and cannot exceed the credit limit.

This time, you are not given skeletons of the new classes or an API. There is enough information in the source code of the classes given to you that you should be able to work out what fields and methods your new classes need. For example, you should create methods:

public void setPeriod(int period)

public int getPeriod()

for getting and setting the interest rate period for each type of account.

Remember, you must not change any of the classes given to you in any way whatsoever except for RunTransactions. You can change that to add your own tests, although by now, you should be thinking of using BlueJ’s unit testing facilities.

Submission instructions

You will submit your assignment to the Give automated marked system.

  1. From within your assignment 3 BlueJ project, select Project -> Create Jar File…
  2. In the Dialog Box that appears:
    1. Set “Main Class” to none
    2. Ensure “Include Source” is checked
    3. Leave “Include Bluej project files” unchecked
  3. Press “Continue”
  4. Save the filename as “assignment3.jar”
  5. Open a web browser and go to the give web site
  6. Log-in with you Z-Pass
  7. Either enter “INFS1609” in for the course, or select INFS1609/INFS2609 from the drop down menu and press “Search for Assignments”. Note INFS2609 students may need to enter “INFS1609” instead of selecting INFS2609 if the assignment is not listed
  8. Select “assignment3” from the next drop down menu and press “Upload my Assignment”
  9. Accept the student declaration
  10. Press “Choose File” and select the “assignment3.jar” file that you saved in step 4
  11. Press “Submit my Files”
  12. Wait for the page to completely load. Then carefully read the output. If the assignment is successful you should see the following lines:
    Checking your submission...
    Checking for relevant classes...
    All files are OK
  13. If the page doesn’t load properly, that is OK just submit the assignment file again.
  14. If you see the final line, everything is good. Otherwise check the output to see what went wrong and resubmit.

Submission notes:

  1. You can submit as many times as you wish, even after the deadline. Only your last submission will be marked.
  2. Make sure you name everything the as instructed, including the classes and the submission file or the submission will not work.
  3. If you have any problems with submission, email the class account

Tutorial – Week 9

Posted by on September 18th, 2011 · Labs

The following exercises are taken from chapter 8 of the textbook.

Exercise 8.4 Open the project dome-v2. This project contains a version of the DoME application rewritten to use inheritance, as described above. Note that the class diagram displays the inheritance relationship. Open the source code of the DVD class and remove the ‘extends Item‘ phrase. Close the editor. What changes do you observe in the class diagram? Add the ‘extends Item‘ phrase again.

 

Exercise 8.5 Create a CD object. Call some of its methods. Can you call the inherited methods (for example, setComment)? What do you observe about the inherited methods?

 

Exercise 8.6 In order to illustrate that a subclass can access non-private elements of the superclass without any special syntax, try the following slightly artificial modification to the CD and Item classes. Create a method called printShortDetails in the CD class. Its task is to print just the artist and the title of a CD on a line by itself. However, because the titIe field is private in the Item class, it will be necessary to add a public getTitIe method to Item. Call this method from printShortDetails to access the title for printing. Remember that no special syntax is required when a subclass calls a superclass method. Try out your solution by creating a CD object. Implement a similar method in the DVD class to print just the director and title.

 

Exercise 8.8 Open the dome-v2 project. Add a class for games and a subclass for video games to the project. Create some video game objects and test that all methods work as expected.

Database inheritance diagram

 

Exercise 8.12 Assume we have four classes: Person, Teacher, Student and PhDStudent. Teacher and Student are both subclasses of Person. PhDStudent is a subclass of Student.

a. Which of the following assignments are legal, and why or why not?

Person p1 = new Student();
Person p2 = new PhDStudent();
PhDStudent phd1 = new Student();
Teacher t1 = new Person();
Student s1 = new PhDStudent();

b. Suppose that we have the following legal declarations and assignments

Person p1 = new Person();
Person p2= new PerSon ();
PhDStudent phd1 = new PhDStudent();
Teacher t1 = new Teacher () ;
Student s1 = new Student();

Based on those just mentioned, which of the following assignments are legal and or why not?

s1 = p1;
s1  = p2;
p1 = s1;
t1 = st;
s1 = phd1;
phd1 = s1;

 

Exercise 8.13 Test your answers to the previous question by creating bare-bones versions of the classes mentioned in that exercise and trying it out in BlueJ

 

Assignment 1 Results

Posted by on September 12th, 2011 · Assignments

Marks for Assignment 1 are now available for collection. Go to the assignment management page: https://cgi.cse.unsw.edu.au/~give/Student/give.php, and select INFS1609 or INFS2609. Then select “assignment1” and press “Collect my Assignment”.

You will be presented with your assignment log. The log contains:

  • Your submitted code
  • Comments from your tutor within the code
  • A summary of the tests and results
  • Output from incorrect tests
  • Your marks
  • Finally comments from your tutor

Your tutor has marked your assignment. Carefully read any comments that your tutor may have added to your log. If you have any questions about the results or comments contact your tutor first.

Tutorial – Week 8

Posted by on September 12th, 2011 · Labs

JUnit Testing

For the exercises this week, download the diary-testing-junit-v2 project. These examples and exercises are based on chapter 6 of the textbook.

  1. Using the diary-testing-junit-v2 project, create a method in DayTest to check that findSpace returns the value of 10 for a one-hour appointment if a day already has a single one-hour appointment at 9 a.m. You must first create the 9 a.m. appointment, then the 10 a.m appointment. Specify assertions for the results of both calls.
  2. Create a test to check that findSpace returns a value of -1 if an attempt is made to find an appointment In a day that is already full.
  3. Create a test class that has Appointment as its reference class. Record separate test methods within It that check that the description and duration flelds of an Appointment object are initialised correctly following its creation.
  4. Create the following negative test in the DayTest class. Create a Day object, a one-hour Appointment object and a two-hour Appointment object. Make the one-hour appointment at 10 a.m. and then try to make the two-hour appointment at 9 a.m. Since this call to makeAppointment should fail, the value to put into the assertion is false. Now run the test. What is shown in the test results window?

 

Model solution for assignment 1

Posted by on September 12th, 2011 · Assignments

You can find a model solution for assignment 1 here.

Tutorial – Week 7

Posted by on August 29th, 2011 · Labs

This week’s tutorial is taken from the textbook, exercises 5.25 – 30 on page 149. They are reproduced below.

The task is to implement a simple phone book where numbers are associated with names, both represented as strings. Your phone book should be able to add a new name/number pair and you should be able to lookup a number, given a name.

    HashMap<String, String> phoneBook= new HashMap<String, String>();

initialises the phone book. The following statements add new entries:

    phoneBook.put("Charles Nguyen", "(02) 9392 4587");
    phoneBook.put("Lisa Jones", "(03) 4536 4674");
    phoneBook.put("William H. Smith", "(07) 5488 0123");

Next, we look up an entry:

    String number = phoneBook.get("Lisa Jones");
    System.out.println(number);

We refer to the name as the key because it is used for the lookup. Given the above, answer the following questions. You will need to use the Java API documentation.

  1. Create a class MapTester in a new project. In it, use a HashMap to implement a phone book. You will have to import java.util.HashMap. In this class, implement two methods:
    public void enterNumber(String name, String number)

    and

    public String lookupNumber(String name)

    The methods should use put and get methods of the HashMap class to implement their functionality.

  2. What happens when you add an entry to a map with a key that already exists in the map?
  3. What happens when you add an entry to a map with two different keys?
  4. How do you check whether a given key is contained in a map? Try it in Java.
  5. What happens when you try to look up a values and the key does not exist in the map?
  6. How do you check how many entries are contained in the map?