Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

can someone make sense of this uni assignment spec?!

Options
  • 02-02-2005 12:54am
    #1
    Closed Accounts Posts: 807 ✭✭✭


    OK recieved a nasty assignment..or it is for me because im still not too good at C# :(

    im gonna post the spec here..im not asking for you to do it for me lol..or ill never figure it out so dont worry im not trying to be that cheeky ;)

    ****************************************************

    You are implementing the account storage class for a bank management system



    The set of behaviours that the customer has asked for is as follows:



    * pay money into the account
    * draw money out of the account
    * find the balance
    * print out a statement
    * change the name and address of the account holder
    * print out the name and address of the account holder
    * change the overdraft limit
    * find the overdraft limit



    There are also some things that the customer is very concerned about:



    * the data in the class should be private and not visible to other programs without the use of methods you will write to provide access.
    * the customer should never be able to draw money out beyond the overdraft limit
    * it should not be possible to set an overdraft limit which is less than a current overdraft
    * it should not be possible to "upset" an account by sending invalid values into the class, as described below



    You are to use a test driven development to produce the code. Every behaviour must be tested by a test class (which you must write) to prove that it works correctly. At least the following tests must be supported:



    * it should not be possible to pay a negative amount into the account
    * it should not be possible to withdraw a negative amount from the account
    * it should not be possible to set the overdraft limit to less than 0 or greater than 10,000
    * it should not be possible to set the name or address of the account holder to empty strings
    * it should not be possible to withdraw more than the overdraft limit
    * it should not be possible to pay in more than 1000 pound at once

    ****************************************************

    i probably could have skipped bits out of that but basicall im not sure what its asking for...i know its asking for a bank account as such but how far do i like..take it :confused: ..it says im implementing the account storage class..which means what exactly?!..i know ive got to do 2 files...1 is the dll...which im sort of coming to terms with..and ones testing but like 1 of my previous programs was to make a game of battleships ..which i obviously knew what it was asking for!...this one..do i have to take it to the point where i can enter some detail it will run through the account testing everything? or what?

    ive had it a few days now and its not good when you cant even make the spec out..ive got the old uni notes out and notepad2 and im gonna have a crack at it now (dying of flu so im not all there anyway but i have to do summat while im off as ive got till the 11th)


    like i said..if you could just outline what that actually means..dying and hardly being able to move means i cant even get to uni to ask anyone! :(


Comments

  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    Basically, its a class with private attributes, get and set methods, and lots of reasonable error detection. You're also required to write a program that shows how this code works, with test values that will show it working without a flaw, and values that will try to break it.


  • Registered Users Posts: 4,276 ✭✭✭damnyanks


    Look into nUnit


  • Registered Users Posts: 2,426 ✭✭✭ressem


    It ain't a nasty assignment, you just need a starter.

    You're using Visual Studio.net or just notepad? I'll assume the former.

    To create the class library DLL you just need to

    Go File >New> Project> Visual C# Projects
    Choose the "Class Library " template
    give your project a name

    Each set of behaviours describes a public method or 2 of your class
    like

    /// <summary>
    /// * pay money into the account
    /// </summary>
    /// <param name="amount"></param>
    /// <returns></returns>
    public bool AddMoney(decimal amount)
    {
    if ((amount <=1000) && (amount>=0))
    {
    bankBalance+=amount;
    return true;

    }
    return false;

    }

    which does the checks for invalid values.
    The actual variable bankBalance and the others have to be private and internal to your class.

    private decimal bankBalance

    To read or alter them from outside you need to go through a public method.

    ---

    The testing part seems to be confusing you the most,

    Create the DLL.
    Add in stub methods for each behaviour that just has entries like
    /// <summary>
    /// * draw money out of the account
    /// </summary>
    /// <param name="amount"></param>
    /// <returns></returns>
    public bool DrawMoney(decimal amount)
    {
    return false;

    }

    Build this file and you'll have a DLL ready to reference from your test program.

    Your test program will be a seperate project that has the
    "using <your.classlibrary.namespace>" and the DLL added as a reference.
    (Project/Add Reference/ Browse for your DLL) and as a file to the project (IN solution explorer, add existing item)

    Now you will be able to call the public methods of the DLL from your test program.
    Your test program can just be a command line function that calls each method a few times with values that should work and should not work saying something like

    Method TestMakeAccountDeposit

    "Called method AddMoney with parameter -1.
    Expected false Got false"
    Previous AccountBalance 0 Expected new AccountBalance 0 Got AccountBalance 0

    "Called method AddMoney with parameter 0. Expected true Got false"
    Previous AccountBalance 0 Expected new AccountBalance 0 Got AccountBalance 0

    "Called method AddMoney with parameter 1. Expected true Got false"
    Previous AccountBalance 0 Expected new AccountBalance 1 Got AccountBalance 0

    Ideally you write the test class entries before the dll code, but for a class they can go hand in hand.


    As for NUnit, get comfortable with this much and you can try adding NUnit tags in later.


  • Closed Accounts Posts: 9,314 ✭✭✭Talliesin


    ViperVenoM wrote:
    im gonna post the spec here..im not asking for you to do it for me lol..or ill never figure it out so dont worry im not trying to be that cheeky ;)
    To prepare you for the real world you should have to deal with a spec written by a committee of technophobic illiterates with opposing political goals within their organisation and a fetish for tech buzzwords that have no bearing on the project whatsoever.

    And a small budget.


  • Registered Users Posts: 640 ✭✭✭Kernel32


    Talliesin wrote:
    To prepare you for the real world you should have to deal with a spec written by a committee of technophobic illiterates with opposing political goals within their organisation and a fetish for tech buzzwords that have no bearing on the project whatsoever.

    And a small budget.

    And two days before you hand it in you should be issued an updated spec with major changes to the core functionality, but no change in the delivery date.


  • Advertisement
  • Registered Users Posts: 2,150 ✭✭✭dazberry


    Kernel32 wrote:
    And two days before you hand it in you should be issued an updated spec with major changes to the core functionality, but no change in the delivery date.

    Spec - Luxury. When I were lad....

    D.


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    due to nasty nasty flu i never got round to it last night..but ill be aving a crack at it now before i run off to bed again dying :mad:

    thanks for the help!, especially ressems rather large post! which although is slightly confusing at first could just get me started! as yes...i dont think its harder then my last assignment as we have covered pretty much all the code in ere before its just knowing where to start with it :(

    as for the post about having to deal with the real world..yeh i know ..but hey ive only been at it a couple of months after never programming before!..give me chance :p

    how silly of me ..i thought a games development course would be fun!

    argh..come on flu...me you..the laptop visual studio and masses of coffee! ive got till the 11th but after the fuss it takes me to write something ill prob be finding problems with it till 3am on the deadline morning so i must get cracking!

    and ive just pre ordered WoW...gotta get that out of my mind! :eek:


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    hmm as usual i cant start the stupid thing....i ended up resorting to notepad2 though as i no longer like using visual net

    i just cannot understand this despite your help...i cant figure out which bits i want in the 2 codes...i know i need to declare things like the balance getbalance...withdraw funds and stuff at the top of the one that becomes the dll....(actually i dont know if ive got this the right way round..ill end up with 1 dll file and 1 .exe file correct?) im presuming the dll file will have everything declared in it..but for instance if i declare:

    public decimal PayInFunds;


    at the top of the dll file..do i then add something like:

    public void PayInFunds ( decimal amount ) {
    balance = balance + amount;
    }

    to it..or does this go somewhere else...

    so im adding this at the top..along with overdraft limits and everything i presume (?)

    then after ive done all this ...do i have another class within this program for such things as:

    storing the name of the account...and changing them..or do these go in the testing..argh! (im not USUALLY this stupid i usually understand the basic idea of a program and i can sort of toddle along but im finding this so fecking hard to understand which is why i cant understand it..if it carries on like this ill prob quit uni :mad: )


    but anyway..in the testing then...how do ..hmm see i cant even explain this ...say i want to test the withdraw bit if ive got :

    public bool WithDrawFunds ( decimal amount ) {
    if (( amount < 0 ) || (amount > 1000)){
    return false ;
    }
    if ( balance >= amount ) {
    balance = balance - amount ;
    return true;
    }
    else {
    return false ;
    }

    how can i make the test go...testing withdraw...trying to take out 1500..then taking out ..letters i guess :s...then taking out negatives...


    argh the spec doesnt even seem TOO hard i just cant understand which is suppose to go in which section i keep getting errors and im hardly writing anything..my total amount of code tonight has equalled 0.4kb :eek:

    any help (again :( ) would be appreciated...after spending the last 2hrs and probably making my flu worse due to not being in bed..i havent achieved anything worth saving ..and its quite depressing with 8 days left :mad: :mad: :mad: :mad:


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    Talliesin, Kernel32.. its like you have a window to my soul! :D

    ViperVenom. Your first problem is from what I can see if you are starting to code without actually writing out a plan of what it is you are going to lay out.

    I recommend you go read up on UML and plan out what you are going to code. It's half the battle. Also have a look at Poseidon (http://www.gentleware.com/) its free, although it only code generates for java. :/ Not sure for .net/C++.

    You don't have much time (how much time did they give you to begin with?). I would spend at least one day planning out what you want to lay out. Another day at least writing out what test scripts you need based on the plan and then leave a day or two for testing/bug fixing.


  • Registered Users Posts: 2,426 ✭✭✭ressem


    Yes, you'll have one DLL and one EXE.

    Dll holds BankAccount class.
    exe creates an instance of the class and calls methods using test cases
    public decimal PayInFunds;


    at the top of the dll file..do i then add something like:

    public void PayInFunds ( decimal amount ) {
    balance = balance + amount;
    }

    No, this isn't C, you don't declare methods. You've created a public and unwanted variable with the same name as the method.

    you should just have
    private decimal balance;

    and PayInFunds should check that you are not paying in an invalid amount, and return a boolean so you can determine whether it succeeded or failed.





    DLL
    namespace MyNamespace.BankManagement
    {
    	using System;
    
    	/// <summary>
    	/// Summary description for BankAccount.
    	/// </summary>
    	public class BankAccount
    	{
    		private decimal balance ;
                    private string accountName;
                    //... other private class data here
    
    
    		/// <summary>
    		///  * pay money into the account
    		/// </summary>
    		/// <param name="amount"></param>
    		/// <returns></returns>
    		public bool PayInFunds (decimal amount)
    		{
    
                         // Add in error checking
                         balance = balance + amount;
                         // Return false until you add the code 
                         // to make this method work.
                          
                          return false; 
                    }
    
    
    		public bool SetName(string inputName)
    		{
                         if( inputName.Length!=0)
                          {
                                 accountName=inputName;
                                 return true;
                          }
                          return false; 
                    }
    
    
    ...
    
    
    EXE
    using System;
    using MyNamespace.BankManagement;
    
    namespace ConsoleApplication2
    {
    	/// <summary>
    	/// Summary description for Class1.
    	/// </summary>
    	class Class1
    	{
    		/// <summary>
    		/// The main entry point for the application.
    		/// </summary>
    		[STAThread]
    		static void Main(string[] args)
    		{
    			string defaultAccountName="my name";
    			string defaultAccountAddress="my address";
    			decimal defaultAccountBalance=50; 
    
    			string retrievedAccountName="FAIL";
    			string retrievedAccountAddress="FAIL";
    			decimal retrievedAccountBalance=-1; 
    			bool returnMethodSuccessful=false;
    
    
    			BankAccount testAccount= new BankAccount();
    			testAccount.Initialise();
    			testAccount.SetName(defaultAccountName);
    			testAccount.SetAddress(defaultAccountAddress);
    			testAccount.SetBalance(defaultAccountBalance);
    
    
    			// test PayInFunds  Method
    			Console.WriteLine("Testing PayInFunds ");
    			retrievedAccountBalance = testAccount.GetBalance();
    			Console.WriteLine("Starting Balance " + retrievedAccountBalance);
    			// Run PayInFunds method. Use a valid value. Expect true back
    			returnMethodSuccessful = testAccount.PayInFunds (50);
    			Console.WriteLine("PayInFunds  returned " + returnMethodSuccessful + ". Expected True");
    ...
    


  • Advertisement
  • Closed Accounts Posts: 17,208 ✭✭✭✭aidan_walsh


    reseem, why not just do the rest of the project for him altogether? :D


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    i wish he would he knows what hes talking about and could probably do it in 20min! :eek:

    Hobbes no we never get much time ive got till next friday...i got it given on ..er either this monday or tuesday cant remember which day but ive been ill all week so ive missed some days at uni :(

    yes i see i wrote out wrong what i meant...i was setting declarations at the top which is VB..we did sort of some at college but only about 1 week :(

    hmm...time to waste another 10hrs or so doing a 10min job...sigh


    but Thanks! ...i hope now you have distinguished what goes in the dll and what goes in the .exe i may ..just may..have a chance!


  • Registered Users Posts: 2,426 ✭✭✭ressem


    Yeah, I know, sucker for a hard case.
    thought it was enough to get over the "what's a dll?" type qns.

    OK how's this instead
    http://www.csharphelp.com/archives2/archive402.html
    especially 3rd tutorial

    If he's actually trying to learn, he can restructure the main routine into methods and consider adding NUnit [Test] tags and NUnit Asserts to these methods in the EXE (just look at the samples provided with NUnit 2.2.0 and you'll get the idea).
    My lack of a social life in college showing?


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    whats a social life...? :p

    i now understand what a dll file is!...im just trying to look around to see what the expected outcome of this assignment is..it just seems the .exe will automatically run through each test saying that they have all passed...and hopefully..none fail...if thats the case..i may have a good chance of doing this now..thanks for the help!..i just got sidetracked with ebay after making a sale though :o

    back to notepad! :)

    -edit-

    Major update!!!!

    now ive sort of figured out that all its suppose to do is create a "test" account and run through various tests making sure you cant screw the account up by entering wrong digits..we are making progress!

    it goes through...creates an new account sets balance to 0...adds 50 in correctly...withdraws £20 correctly leaving £30...oh im moving up now...get the delights of trying to break the thing now by taking too much out..but the fact ive got it doing something is excellent!!!!

    i dont get where im suppose to let the user change name or anything since its suppose to be a sort of automated test procedure but ill cross that bridge when i come to it..so far so slowly..but surely! good :D


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    argh..help overdraft has been bugging me for a while!

    dll -

    private decimal overdraft = 0;
    public decimal GetOverdraft() {
    return overdraft;
    }

    public bool SetOverdraft(decimal amount) {
    if ((amount < overdraft) || (amount > 10000)) {
    return false;
    }
    if ((amount > overdraft) && (amount <= 10000)) {
    (overdraft == amount); <<<<<<<<< bugger!
    return true;

    }
    else {
    return false;

    now as you see as noted..that line ive tried about 20 different ways of making the amount to be set as the overdraft but to no aid...in my .exe i have:

    test.SetOverdraft(100);
    Console.WriteLine("For this test i will now add an overdraft limit of £100");
    Console.WriteLine("Expected Outcome - Account should now be £1100");
    Console.WriteLine("Balance = " + "£"+test.GetBalance()+ " (£"+ test.GetOverdraft() + " is the Overdraft)");
    if (test.GetBalance() !=1100) {


    but of course it always fails because it refuses to set the overdraft..i actually got it 1 way of setting it to the £100..but then that refused to add to my balance bit which is ere:

    public decimal GetBalance() {
    return balance;

    i tried

    public decimal GetBalance() {
    return balance + overdraft;

    but ..er nope..what stupid thing have i overlooked? :confused: (it has been going well! ive got it to pay show and withdraw from the balance you cant take a negative number out or anything thats on the uni spec...just this guys being a little bugger :()


  • Registered Users Posts: 21,264 ✭✭✭✭Hobbes


    (overdraft == amount); <<<<<<<<< bugger!

    Wouldn't that return a boolean, which wouldn't be assigned to anything (notsure what you are coding in). == is an equates and = is an equals.


  • Registered Users Posts: 2,426 ✭✭✭ressem


    And besides that, the logic is a bit off.

    You can't set the overdraft limit to 0, as required by the spec.

    Assume that SetOverdraft will be called more than once.
    If the first time you set the limit to say 5000, then you can't put it back down to between 0 and 5000. (first if statement will return false because you assume the overdraft variable will always be the lower limit (even though you've just changed it), instead of keeping it at 0 as specified in the spec)

    So
    SetOverdraft (3456) will return true
    but then calling
    SetOverdraft (3400) will fail.


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    * it should not be possible to set an overdraft limit which is less than a current overdraft

    i was just going by that line :confused:

    Hobbes i was trying alsorts

    overdraft == amount
    amount == overdraft
    overdraft = amount
    amount = overdraft

    etc etc....im pretty sure its meant to be just 1 = but as i posted it in at the time i had left it on == :rolleyes:


  • Registered Users Posts: 2,426 ✭✭✭ressem


    Yeah, you're getting "overdraft" (i.e a negative value in Account balance ) and "overdraft limit" mixed up. You only need "overdraft limit" and "balance".

    As you withdraw money "balance" becomes a negative number until it reaches "0 - overdraft limit" after which withdraw fails.


    The SetOverdraftLimit method that you are asked for needs to check that


    /// Set the maximum amount that balance can drop below zero.
    if
    amount >= 0 AND amount <= 10000 AND amount >= (0 - balance)
    then
    overdraft = amount;
    else fail


  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    ohhh i see...well i think ..ill try putting it into practice later..gotta actually go to uni for 2hrs now see what ive missed out since im only semi dying ;)


    cheers again..i swear..i dunno where id be without these boards :)

    ...funny im getting overdraft a bit confused with this..since im so far into my own :eek:


  • Advertisement
  • Closed Accounts Posts: 807 ✭✭✭ViperVenoM


    bugger bugger bugger..1 more small problem then im done :eek:

    (it seems its changed now and we are not setting up the actual account until a few weeks time when we learn to make a GUI and everything for it so for now its just test outputs)

    im having a few problems with the overdraft..ive got it to display the overdraft and add it to the balance now but it still wont let me withdraw into the overdraft..but anyway

    my problem is setting the account name..i know i could do what you have done and set it to a default name (if i cant figure this out i probably just will)

    but you see your not allowed to have it as an empty string so i tried something like:

    private string AccountName;

    public string GetAccountName() {
    return AccountName;
    }

    public bool SetAccountName (string setName) {
    if (setName.Length == 0) {
    return false;
    }
    if (setName.Length != 0) {
    setName = AccountName;
    return true;
    }
    else{
    return false;
    }

    but it seems to never accept something i put in the test side..i dont think its accepting anything..or ive done it wrong..i think that "length == 0" thing is correct as we used it on an earlier program but before it was easier as it was all in 1 file so i could just stick it in a loop till it wasnt an empty string...is there anyway i can do a loop to stop an empty string...or do i have to do it another way will a dll file?


  • Registered Users Posts: 2,426 ✭✭✭ressem


    setName = AccountName;

    The equals means that the left hand side is set to the value of the right hand side.

    Try
    AccountName = setName;

    By the way, trivial point, usually you'll start variable names with a lower case letter & you might want to get practice using the visual studio debug mode especially the step through (F10) and watch variable functions (under debug/windows menu).


Advertisement