Business Programming

Course announcements for INFS1609 and INFS2609

Business Programming random header image

Assignment 2

Posted by on August 24th, 2011 · Assignments

Change Log

  • 2011-09-02 Added submission instructions

Task

This assignment extends assignment 1. Now that you have defined classes for accounts and transactions, the next step is to use collections to make a simple journal and ledger. A journal will be implemented as an ArrayList of transactions. A ledger will be implemented as a HashMap containing accounts, indexed by their account number. Why use different types of collections? For the journal, we only need to access the transactions sequentially, whereas accounts in the ledger have to be accessed by account number.

Your program will provide the following operations:

  • create a new journal
  • create a new ledger
  • create a new transaction and add it to a journal
  • process all the transactions in a journal, to update the accounts in the given ledger

When an individual transaction is processed, in addition to updating the balance of the account, the transaction should be stored in an ArrayList associated with the account, so that a report can be produced that shows all the transactions for each account. You do not have to write the report method. That will be provided.

Here as an example of the RunTransactions class for this assignment.

public class RunTransactions
{
    static void main()
    {
       // Create a new ledger, L
       Ledger L = new Ledger();

       // Create two new accounts with the given account numbers
       // Add the accounts to the ledger
       L.addAccount(1234, new Account(1234, 20));
       L.addAccount(6778, new Account(6778, 10));

       // Create a new journal, J.
       Journal J = new Journal();

       // Transactions consist of an account reference, an amount
       // and in this assignment, transactions also have a string describing
       // the transaction.
       // Each transaction is added to the journal.
       J.addTransaction(new Transaction(1234, 20, "deposit on 3/9/2011"));
       J.addTransaction(new Transaction(6778, 10, "deposit on 4/9/2011"));
       J.addTransaction(new Transaction(6778, -50, "withdrawal on 6/9/2011"));

       // Transactions must contain a "process" method that is called to
       // actually perform the transaction.
       // A journal also has its own process method that calls the transaction process
       // method for each transaction, in the order that the transaction was created.
       J.process(L);

       // For each account in the ledger, print the opening balance, list all the
       // transactions for that account and print the closing balance.
       // This method is provided for you in the Ledger class.
       L.report();
    }
}

You can download a skeleton project here. You should write methods that conform to the specifications here. This is a zip file containing the documentation of a “standard” solution. When you unzip the ass2_doc.zip file, open index.html and you will be able to browse through all the classes and methods. You must implement all of the methods as specified, except the report and toString methods, which have already been provided.

FAQ

  1. What is the format of the output?
    We have provided you with all of the report methods. You should print no additional output.
  2. Is the Unique Account Identifier (key) for the ledger hashmap the same as the account number?
    Yes

Submission instructions

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

  1. From within your assignment 2 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 “assignment2.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 “assignment2” from the next drop down menu and press “Upload my Assignment”
  9. Accept the student declaration
  10. Press “Choose File” and select the “assignment2.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 6

Posted by on August 21st, 2011 · Labs

Catch-up Week

This week, we will finish off the exercises left over from last week and any other work left-over from previous tutorials.

Additional Consultation Hour

Posted by on August 15th, 2011 · Announcements

Tim is running a second consultation hour from Thu 4-5pm in K17-403 each week.
Claude’s consultation hour will still be running on Tue 2-3pm in K17-403 each week.

Tutorial – Week 5

Posted by on August 14th, 2011 · Labs

Your task this week is to implement a program to represent decks and hands of playing cards.

  1. Download the cards.zip file and uncompress it. It contains an incomplete BlueJ project called cards.
  2. Open the project and inspect the classes:
    • Card – this represents a single playing card.
    • Deck – this represents a deck of cards. The constructor has been written but the methods need to be completed.
    • Hand – this represents a hand of cards drawn from the deck. The fields, constructor and methods all need to be implemented.
  3. Complete these classes following the comments. Do the Deck class first then the Hand class.

To complete the Deck.draw() method you will need to use the Random class in the Java API. This class provides a random number generator to pick random numbers.

To use this class you will have to import it, by putting the line:

import java.util.Random

at the top of your code.

Read the documentation to find out what constructors and methods the Random class provide.

To see what the class does, try typing the following into the Codepad:

import java.util.Random;
Random rng = new Random();
rng.nextInt(6)
rng.nextInt(6)
rng.nextInt(6)
rng.nextInt(20)
rng.nextInt(20)

 

Assignment 1 FAQ

Posted by on August 8th, 2011 · Assignments

An FAQ has been added to the assignment 1 spec page. Please consult this for answers to common questions before emailing your tutor or the course account.

Consultation Times

Posted by on August 6th, 2011 · Announcements

Claude’s consultation time is 2-3pm Tuesdays in K17-403.

Note: This time may change when he takes over the lectures.

Tutorial – Week 4

Posted by on August 6th, 2011 · Labs

Task 1: Universities

Suppose we were writing a program to administer a university. Discuss:

  • What are the different levels of abstraction we might use to represent the university?
  • Choose an object at the mid-level of your hierarchy. What kind of public interface might it provide? What private implementation details might it hide?

Task 2: Return to the Ticket Machine

Go back to the ticket machine project you worked on in last week’s tut.

  1. Create a new class Ticket which represents a ticket.
  2. Create appropriate fields. What information shoud a Ticket carry?
  3. Create a constructor to initialise these fields.
  4. Now modify purchaseTicket on the TicketMachine class so that it creates a new Ticket object and returns it, rather than printing it.

Let’s suppose now that a ticket has 10 charges. Each time we use it, one charge is lost.

  1. Change your Ticket class to track charges. What changes do you need to make to do this?

Now let’s add a recharge method to the TicketMachine. It should take a Ticket as a parameter and reset its charges to 10 but at the cost of 1/10th of the ticketPrice for every charge added (if the user has enough balance). Implement this in stages:

  1. Make the method just recharge the Ticket for free.
  2. Compute how much the recharge will cost. You will need to use an accessor method on the Ticket to find out how much charge it has.
  3. Add a test to see if the user has enough balance.
  4. If there is not enough balance print an error message and do not recharge.
  5. Subtract the charge from the balance.

Task 3: Clock (if time permits)

Take a look at the clock project from Chapter 3 of the textbook.

  1. Investigate the NumberDisplay class first. How does it work?
  2. Look at the setValue method. What does the && operator do? This is a boolean operator. Try experimenting with it in the Code Pad.
  3. Look at the increment method. What does the % operator do? Try experimenting with it in the BlueJ Code Pad.
  4. Now take a look at the ClockDisplay class. Try to understand how it works.
  5. ClockDisplay has two constructors. How do they differ?
  6. The second constructor does not call updateDisplay. Is this a bug? Why/why not?
  7. Change this class to have a seconds field as well as hours and minutes.
  8. Change the class to show a 12 hour clock with AM/PM.

Assignment 1 – FINAL

Posted by on July 31st, 2011 · Assignments

NOTE: check this web site regularly for updates and clarifications to the assignment specification.

Due Date: Friday week 5 (23:59:59 19 August 2011)

Change Log

  • 2011-08-04 Clarified output of report for the sample program
  • 2011-08-03 Final version, including new report method
  • 2011-08-02 Bugfix: Corrected captalised Fred to fred

Task

Suppose you are designing a program for an automated teller machine. The ATM generates transactions that are sent to the banks central computer for processing.

In this assignment, you will create two classes, “Account” and “Transaction”. An Account object should have a unique account number, which can be represented by an integer, and a balance. Initially the balance is zero. A Transaction object should have an amount being transacted and a reference to the Account class associated with the transaction.

Here is an example of the two classes being invoked:

/**
 * This class contains a main method that calls methods in the classes you will write.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public class RunTransactions
{
    static void main()
    {
       // Create two new accounts with the given account numbers
       Account fred = new Account(1234);
       Account jim = new Account(6778);

       // Provide accessories methods for account information.
       int accountNumber = fred.getAccountNumber();
       float balance = fred.getBalance();

       // Transactions consist of an account reference and an amount
       Transaction t1 = new Transaction(fred, 20);
       Transaction t2 = new Transaction(jim, 10);
       Transaction t3 = new Transaction(jim, -20);

       // Transactions must contain a "process" method that is called to
       //  actually perform the transaction.
       // A transaction should not be allowed if it results in a negative balance.
       t1.process();
       t2.process();
       t3.process();

       // Print out a report of the account balance.
       // The format should be like this: Account 6778 has balance $20.0
       fred.report();
       jim.report();
    }
}

Download this file. It contains a BlueJ project with just the RunTransactions class. You must create your own Account and Transaction classes. You can create whatever fields and methods you think appropriate but you must provide methods that can be called exactly as above.

The report method should print out a simple message giving the account number and balance. The format should be

       Account <account number> has balance $<account balance>

For example, the output of the reports from the above sample code should be:

       Account 1234 has balance $20.0
       Account 6778 has balance $10.0

You will learn about main methods and the static qualifier in later lectures. For now, you only need to know that when you right click on the RunTransactions class, you will see an item in the menu void main(). Clicking on this will run the main method, which will call your code.

You may change the main method to test your code with different combinations of accounts and transactions. Only remember that you must use exactly the same names of classes and methods and the types of arguments are return values must be identical.

When you submit your assignment, we test your code with different main methods.

Submission instructions

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

  1. From within your assignment 1 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 “assignment1.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 “assignment1” from the next drop down menu and press “Upload my Assignment”
  9. Accept the student declaration
  10. Press “Choose File” and select the “assignment1.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 Account and Transaction 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 (“Account” and “Transaction”) the submission file (“assignment1.jar”) or the submission will not work.
  3. If you have any problems with submission, email the class account

Marking Scheme

The maximum mark for this assignment is 10. Marks will be awarded as follows:

Performance (6 marks)
– for a program that produces the correct results under all tests
Style (2 marks)
– for the structure of your classes, layout and readability
Comments (2 marks)
– for a well commented program

FAQ

  1. Will transactions use decimal values?
    Yes. For the purposes of this assignment, you can assume that floats will be of a sufficient precision.
  2. How should we deal with printing floats?
    Just use the default output generated by Java for printing floats
  3. Does the dryrun test my program?
    No. The dryrun only checks that you have submitted right files. We will run the testing for marking after the deadline for the assignment has passed.

Tutorial Week 3 – Designing Classes

Posted by on July 28th, 2011 · Labs

Understand Assignment 1

  1. Follow the assignment 1 instructions to download the skeleton project.
  2. Make sure you understand what is required. If not ask your tutor.

Investigating the TicketMachine:

  1. Download the TicketMachine project we have been building in lectures. Unzip it on your desktop and open the project with BlueJ.
  2. Create an instance of the TicketMachine class.
  3. Experiment with the addMoney() method. What happens if you:
    • Add 0 cents?
    • Add an negative amount?

    Is this behaviour correct?

  4. Experiment with the purchaseTicket() method. Does it work correctly? Try a number of different tests to make sure.
  5. Open up the source and place a breakpoint at the beginning of the purchaseTicket() method by clicking in the grey bar on the left. A little stop sign should appear.
  6. Call the method again and use the Debugger to step through the code.
  7. Try this with different balances to see how the execution varies.
  8. There is a bug in this method. Can you find it?

Extending the TicketMachine

Let us extend the ticket machine to keep track of the total amount of cash collected and to allow us to change ticket prices.

  1. Add a new field to the class to store the total cash collected.
  2. When does this value change? What methods will you need to modify to track these changes?
  3. Add a new accessor method getTotal() to return the value.
  4. Test your code with a variety of method calls to make sure it does the right thing.
  5. Add a new mutator method setPrice() to allow you to change the ticket price.
  6. What happens if you set the ticket price to zero? a negative number?
  7. Add a conditional statement to set-price to stop the price from being set to a negative value.

Design a Class to represent an E-Book.
It should record the following information:

  • An author
  • An title
  • The number of pages
  • The current page being read.

Implement your class in the following steps:

  1. Create a class definition with an appropriate name.
  2. Add appropriate fields. What types will they have? What names will you give them?
  3. Create a constructor to initialise these fields. What starting values will you use?
  4. Create accessor methods to access these fields.
  5. Create mutator methods to allow the use to:
    • turn pages forwards and backwards
    • jump to a specific page
  6. What should happen if they try to access a page outside of the sensible range? How can you implement this?
  7. Create several different books to test your code. What happens if:
    • Your book has only one page?
    • Your book has no pages?
    • Your book has 1000000000000000000000 pages?
  8. Comment your class to describe what it is for and what each of your methods does.

 

Week 2 Lecture Notes

Posted by on July 27th, 2011 · Announcements

Lecture notes for Week 2 are now linked under the Lecture Notes page