COMP1400 – Programming for Designers

Class announcements for Programming for Designers

COMP1400 – Programming for Designers random header image

Assignment 2 – Classes and Objects

Posted by on September 5th, 2013 · Assignments

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

Due Date: Sunday week 8 (23:59:59 22 September 2013)

ChangeLog:

  • 11-09-2013: Submission for Assignment 2 enabled

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 accessor 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 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 “COMP1400” in for the course, or select COMP1400 from the drop down menu and press “Search for Assignments”. Note COMP1400 students may need to enter “COMP1400” instead of selecting COMP1400 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 Account.java
Account.java Compiled Sucessfully
Checking for Transaction.java
Transaction.java Compiled Sucessfully
Sucessfully compiled against sample RunTransactions.java

All files are OK
  1. If the page doesn’t load properly, that is OK just submit the assignment file again.
  2. 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

No Comments so far ↓

There are no comments yet...Kick things off by filling out the form below.

You must log in to post a comment.