I have to build an ATM simulator using c# need help

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 9876 Views - Last Post: 09 July 2012 - 02:11 PM Rate Topic: -----

#1 Niceman99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 07-July 12

I have to build an ATM simulator using c# need help

Posted 07 July 2012 - 12:20 PM

Im new at c# and new at programming when i started this course i hd so much going on my family life that i havent pay much attention to my studies,,,,
And now that i need to write this project i see i needed to pay more attention...
I dont want to get it done by somebody else.
I want help and it may be alot of help.
So far i have done the windows form and everything works now i need to write he classes .
Where is a bit harder is on the strings i know it should be easier its not
im stuck again ,i have build the windows form 

now i need to create the classes here is what i need

Class library

Account class

 properties: pinNumber, accountNumber, accountBalance, maximumWithdrawal, maximTransferAmaount.

methods: withdraw(amount); deposit(amaount); transferIn(amount); transferOut(amaount);. you will need the folowwing to return values: Get pin , Get account number, and get balance.

chequing class

inherits from account

property: maximumbillamaount

constant properties: interestrate.

methods: payinterest()

bank class

inherits from account

constant properties: maximum topup, refillamount

methods: refillATM()

chequingaccounts class

this class needs to add a chequing account and to return a chequing account(using the index or key depending upon type of collection used)

savingaccounts class

this class needs to add a saving account and to return a saving account(using the index or key depending upon type of collection used)

dailybalance class

property: atmdate ,atmbalance

constant property: minimumamount

methods: updatedailybalance() to update atmbalance when supervisor fills up ATM

dailybalances class

this class needs to add a daily balance , and to return a daily balance(using the index or key depending upon type of collection used)

customer class

properties: name,pinnumber

methods: may need to return strings with getname and getpinnumber

customers class

this class needs to add a customer account , and to return a customer (using the index or key depending upon type of collection used)

i need ATM MANAGER CLASS AS WELL

WILL WRITE 

Is This A Good Question/Topic? 0
  • +

Replies To: I have to build an ATM simulator using c# need help

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3553
  • View blog
  • Posts: 11,017
  • Joined: 05-May 12

Re: I have to build an ATM simulator using c# need help

Posted 07 July 2012 - 12:27 PM

The phrasing of your question looks awfully like a Gimme the Codez post, but I'll give you the benefit of the doubt.

It may look overwhelming, but work on it one class at at time.

Start with the Customer class since it looks the simplest. You have the description of what the class needs. Your teacher much have gotten as far as at least teaching you how to write a basic class. So post what your Customer class code would look like.

Once you get that done, we can move on to the other classes listed above.

This post has been edited by Skydiver: 07 July 2012 - 12:29 PM

Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: I have to build an ATM simulator using c# need help

Posted 07 July 2012 - 12:47 PM

90% or more of the problems we see here are because rookies don't stop and plan nor block out their code into logical segments.
This article should help you see a way to block out your code by stubbing out the methods and logic, then filling in each method as you research it:
This is the 'Help me with my homework' article you wanted.

Also, this is a very common project that we see every semester.
If you do a search for "ATM Simulator" you will find at least a dozen threads on this that should get you started. (The search box is at the top of the page)
Was This Post Helpful? 0
  • +
  • -

#4 Niceman99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 07-July 12

Re: I have to build an ATM simulator using c# need help

Posted 08 July 2012 - 09:08 AM

View PostSkydiver, on 07 July 2012 - 12:27 PM, said:

The phrasing of your question looks awfully like a Gimme the Codez post, but I'll give you the benefit of the doubt.

It may look overwhelming, but work on it one class at at time.

Start with the Customer class since it looks the simplest. You have the description of what the class needs. Your teacher much have gotten as far as at least teaching you how to write a basic class. So post what your Customer class code would look like.

Once you get that done, we can move on to the other classes listed above.

i have written this
no idea if its any good
Getname neitgher GETpin works i know.
am i in the right direction?

View PostNiceman99, on 08 July 2012 - 09:07 AM, said:

View PostSkydiver, on 07 July 2012 - 12:27 PM, said:

The phrasing of your question looks awfully like a Gimme the Codez post, but I'll give you the benefit of the doubt.

It may look overwhelming, but work on it one class at at time.

Start with the Customer class since it looks the simplest. You have the description of what the class needs. Your teacher much have gotten as far as at least teaching you how to write a basic class. So post what your Customer class code would look like.

Once you get that done, we can move on to the other classes listed above.

i have written this
no idea if its any good
Getname neitgher GETpin works i know.
am i in the right direction?

sorry here its..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ATM
{
    class Customer
    {
        private string name;
        private double PINNumber;

        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                name = value;
            }
        }
        public double PinNumber
        {
            get
            {
                return PINNumber;
            }
            set
            {
                PINNumber = value;
            }
        }

        public Customer()
        {
        }

        public Customer(string customername, double passw)
            
        {
            name = customername;
            PINNumber = passw;
        }

      /*  public override string ToString()
		{
            string customerInformation = "\nName: " + //base.FirstName + " " +
            //base.name + "\nName: " + name; 
					
			return customerInformation;
		}
       **/


    }
}

This post has been edited by tlhIn`toq: 08 July 2012 - 09:10 AM
Reason for edit:: [code] your code here [/code] tags added.

Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: I have to build an ATM simulator using c# need help

Posted 08 July 2012 - 09:11 AM

Please use code tags. Its posted everywhere include the textbox where you type your post.

Attached Image
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: I have to build an ATM simulator using c# need help

Posted 08 July 2012 - 09:20 AM

So far your customer class looks good. Obviously it needs a lot more items. YOu might consider a first and last name instead of just one combined. You'll want an account number. And methods for adding funds, subtracting funds and getting the current balance.


It also looks like you were having trouble overriding .ToString(). maybe this will help

public override string ToString
{
   return String.Format("{0}, {1}", lastName, firstName);
}


As a rule you don't try to add labels like "Name: " in .ToString() because the class doesn't always know how it will be used. ITs not the job of the class to add this information. If you were going to make a table of all your customers it would look silly to have "Name: " on every row when their is a column header for that

----------------------------------
|   name           | Account NO   |
|Name: tlhIn`toq   | 13465        |
|Name: bob         | 45678        |
----------------------------------


So just return the information, and let the method getting the information worry about how to use it and label it.
Was This Post Helpful? 0
  • +
  • -

#7 Niceman99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 07-July 12

Re: I have to build an ATM simulator using c# need help

Posted 08 July 2012 - 06:10 PM

i have written some classes and i have run into trouble.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ATM
{
    class Chequing : Account
  {
     //   public void Add(Account allaccounts)
     //   {
    //        List.Add(allaccounts);
       // }
        // public Account()
        //{


        //  }
        public Account this[int accountIndex]
        {
            get
            {
                return (Account)List[accountIndex];
            }
            set
            {
                List[accountIndex] = value;
            }
        }
    }
}



i get this error


""""Error 1 Using the generic type 'System.Collections.Generic.List<T>' requires 1 type arguments""""
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3553
  • View blog
  • Posts: 11,017
  • Joined: 05-May 12

Re: I have to build an ATM simulator using c# need help

Posted 09 July 2012 - 12:32 AM

On which line is the error pointing to?

Can you show us your Account class? I'm asking because it looks like you are hoping to use a property name List in the Account class. If that's not the case, then you'll have to declare a class variable or property named List. Usually, though, it's not a good idea to name methods and properties the same as common types. So instead of List, you should really name the property Accounts.
Was This Post Helpful? 0
  • +
  • -

#9 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5805
  • View blog
  • Posts: 12,644
  • Joined: 16-October 07

Re: I have to build an ATM simulator using c# need help

Posted 09 July 2012 - 03:40 AM

Your Chequing makes no sense. What the hell does this[] have to do with anything?

Just walk through your own text:
// chequing class
// inherits from account
class Chequing : Account {
	
	// property: maximumbillamaount
	public double MaximumBillAmount { get; set; }
	// constant properties: interestrate.
	public double InterestRate { get; private set; }
	
	// methods: payinterest()
	
	public void PayInterest() { /* your code here */ }



What we are sorely lacking here is a constructor. We'd need to know the basics of Account, but it would most likely look something like:
public Chequing(int pinNumber, int accountNumber, int maximumWithdrawal, int maximTransferAmaount, double interestrate) :
	base(pinNumber, accountNumber, maximumWithdrawal, maximTransferAmaount) 
{
	this.InterestRate = interestrate;
}
// also, optional
public Chequing(Account acct, double interestrate) :
	base(acct) 
{
	this.InterestRate = interestrate;
}



In both cases, we're making assumptions about what Account's constructor looks like.

Before you even need to worry about the code in the methods, you can flesh out the syntax of the classes. You've already been given that.

Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#10 Niceman99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 07-July 12

Re: I have to build an ATM simulator using c# need help

Posted 09 July 2012 - 11:56 AM

View PostSkydiver, on 09 July 2012 - 12:32 AM, said:

On which line is the error pointing to?

Can you show us your Account class? I'm asking because it looks like you are hoping to use a property name List in the Account class. If that's not the case, then you'll have to declare a class variable or property named List. Usually, though, it's not a good idea to name methods and properties the same as common types. So instead of List, you should really name the property Accounts.

here its i know i need to focus alot more on this and im trying i dont completely get it yet...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ATM
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    public  class Account
    {
        public string PinNum = "";
        public double AccNum = Convert.ToDouble("");
        public double AccBal = Convert.ToDouble("");
        public double maxWithd = Convert.ToDouble("");
        public double maxTrans = Convert.ToDouble("");


  //  public void  Withdraw();
    
    
  //  private void Deposit();

   // private void transferOut();



        public string PinNumber
        {
            get
            {
                return PinNum;
            }
            set
            {
                PinNum = value;
            }
        }

        public double AccountNumber
        {
            get
            {
                return AccNum;
            }
            set
            {
                AccNum = value;
            }
        }
         public double AccountBalance
        {
            get
            {
                return AccBal;
            }
            set
            {
                AccBal = value;
            }
        }

        public double maximumwithdrawal
        {
            get
            {
                return maxWithd;
            }
            set
            {
                maxWithd = value;
            }
        }
        public double maximumtransfer
        {
            get
            {
                return maxTrans;
            }
            set
            {
                maxTrans = value;
            }
        }

        public Account()
        {

        }
    
        public Account(string passw, double accnumb,double balacc,double withmax,double transmax)
        {
            PinNum = passw;
            AccNum = accnumb;
            AccBal = balacc;
            maxWithd = withmax;
            maxTrans = transmax;
            

        }
      

        public override string ToString()
        {
            return AccNum + " " + AccNum + AccBal;
        }
        
    }
      

}

Was This Post Helpful? 0
  • +
  • -

#11 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3553
  • View blog
  • Posts: 11,017
  • Joined: 05-May 12

Re: I have to build an ATM simulator using c# need help

Posted 09 July 2012 - 12:00 PM

I don't mean to confuse you more, but you should never store money values in a double type. This is because the floating point values are approximations rather than exact values. In C#, use the decimal type instead.
Was This Post Helpful? 0
  • +
  • -

#12 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3553
  • View blog
  • Posts: 11,017
  • Joined: 05-May 12

Re: I have to build an ATM simulator using c# need help

Posted 09 July 2012 - 12:08 PM

As for the AccountNumber in the account class, do you really want to use a double? Most banks I know of use a string of numbers. For simplicity, you could just use an int.

So looking on your Account class, why is your Chequing class trying to use a List that doesn't exist in the account class. Additionally, step back and think about it: why does the Chequing class need a list of accounts when the Chequing class is-a Account, and an account represents a single bank account. Wouldn't it make more sense for the Bank class to have a collection (perhaps a List) of Accounts?

(As an aside, I have no idea why your instructor wants the Bank class to inherit from the Account class. To me, they are separate concepts, but that's just me.)
Was This Post Helpful? 0
  • +
  • -

#13 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: I have to build an ATM simulator using c# need help

Posted 09 July 2012 - 12:08 PM

What the frak? Why are you initializing numeric values by converting a string?

Quote

015 public double AccNum = Convert.ToDouble("");


Just set it equal to a number
public double AccNum = 0;

Another 'What the frak?'
107 return AccNum + " " + AccNum + AccBal;
What do you think this is going to produce? Because here's what I see;
when AccNum = 123456789
and AccBal = $152.00
then .ToString() = "12345679 123456941"
What is the reason behind adding the balance to the account number?

This post has been edited by tlhIn`toq: 09 July 2012 - 12:10 PM

Was This Post Helpful? 0
  • +
  • -

#14 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5481
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: I have to build an ATM simulator using c# need help

Posted 09 July 2012 - 12:17 PM

View PostSkydiver, on 09 July 2012 - 01:08 PM, said:

As for the AccountNumber in the account class, do you really want to use a double? Most banks I know of use a string of numbers. For simplicity, you could just use an int.


Uh... No to the int, yes to the string. If you have an account number of 000222546 and you store it as any of the numeric types it will drop the leading zeros. You need it to be a string so it retains them.

Quote

(As an aside, I have no idea why your instructor wants the Bank class to inherit from the Account class. To me, they are separate concepts, but that's just me.)

Agreed! Bank inheriting from account is idiotic and makes me think the instructor doesn't have a good understanding of the subject matter. That's like saying that an 'engine' should inherit from a 'truck'. Sure they are in some way related, but one is not the decedent of the other.

You would inherit like this:
Class Animal
Class Canine : Animal
Class Poodle : Canine


But you wouldn't do:
Class fur
Class Poodle : fur

Because it just makes no sense and is not how these object actually relate.


Maybe this will help your understanding of classes:

Think of objects in coding just as you would objects in the real world.

A Dodge Ram is an object.
It is made up of smaller objects: Engine, doors, tires
Each of those is made up of smaller objects: Bolts, pistons, etc.

Objects in coding can inherit from each other, usually from the general to the specific.

  • Class vehicle
    • Class truck : vehicle
      • Class Ram : Truck
        • class 2500FWD : Ram


A class is the blueprint for instanciating (making an instance of) the object.

DodgeRam is a class describing how to make an instance, but itself is not an actual thing you can interact with.

myDodgeRam is an instance of a the class DodgeRam

I can do things with the object instance myDodgeRam

myDodgeRam.SerialNumber = 123456789;
myDodgeRam.FillUpTank();
float fuelLevel = myDodgeRam.FuelTankPercentageFull;
if (myDodgeRam.IsReady) myDodgeRam.StartEngine();


Anything defined in the base class is available to a child.

class truck : vehicle
{

    public float FuelTankPercentageFull
    {
       get; set;
    }
}

class DodgeRam : truck
{
    // I don't have to define a FuelTankPercentageFull here because I inherit it from my parent
}


Methods defined as virtual in the base class can be overridden by the child class (at least in .NET languages like C#). This is often to account for more specific needs.

class truck : vehicle
{

    public virtual bool StartEngine()
    {
       // Do something to start the engine
       return true; // No checks or requirements
    }
}

class DodgeRam : truck
{
    public override bool StartEngine()
    {
        // Do a safety check first
        if (IsSeatBeltsEngaged && IsFootOnBrake)
        { 
            return true;
        }
        return false;
    }
}


You can even have a child class call the base classes methods which is often the smart way to go.

class truck : vehicle
{

    public virtual bool StartEngine()
    {
       // Notice there are no safety checks before trying to start up.
       try
       {
          // Do something to start the engine
          return true; // because we succeeded
       }
       catch(exception error)
       {
           return false; // because there was an error
       }
    }
}

class DodgeRam : truck
{
    public override bool StartEngine()
    {
        // Do a safety check first
        if (IsSeatBeltsEngaged && IsFootOnBrake)
        { 
            return base.StartEngine();
            // Now all the electrical work is in the base class
            // and not repeated in every child.
        }
    }
}

Was This Post Helpful? 0
  • +
  • -

#15 Niceman99  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 07-July 12

Re: I have to build an ATM simulator using c# need help

Posted 09 July 2012 - 12:21 PM

View PostSkydiver, on 09 July 2012 - 12:08 PM, said:

As for the AccountNumber in the account class, do you really want to use a double? Most banks I know of use a string of numbers. For simplicity, you could just use an int.

So looking on your Account class, why is your Chequing class trying to use a List that doesn't exist in the account class. Additionally, step back and think about it: why does the Chequing class need a list of accounts when the Chequing class is-a Account, and an account represents a single bank account. Wouldn't it make more sense for the Bank class to have a collection (perhaps a List) of Accounts?

(As an aside, I have no idea why your instructor wants the Bank class to inherit from the Account class. To me, they are separate concepts, but that's just me.)

i think im more messed up he doesnt want to inherit im JUST confuse...i have been trying and i dont tottally understand
so thats why its all messed up
here is something new i wrote mostly copy and paste from a few posts up

THIS IS THE ACCOUNT CLASS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ATM
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    public  class Account
    {
        public int PinNum  ;
        public int AccNum  ;
        public int AccBal ;
        public double maxWithd ;
        public double maxTrans ;


  //  public void  Withdraw();
    
    
  //  private void Deposit();

   // private void transferOut();



        public int PinNumber
        {
            get
            {
                return PinNum;
            }
            set
            {
                PinNum = value;
            }
        }

        public int AccountNumber
        {
            get
            {
                return AccNum;
            }
            set
            {
                AccNum = value;
            }
        }
         public int AccountBalance
        {
            get
            {
                return AccBal;
            }
            set
            {
                AccBal = value;
            }
        }

        public double maximumwithdrawal
        {
            get
            {
                return maxWithd;
            }
            set
            {
                maxWithd = value;
            }
        }
        public double maximumtransfer
        {
            get
            {
                return maxTrans;
            }
            set
            {
                maxTrans = value;
            }
        }

        public Account()
        {

        }
    
        public Account(int passw, int accnumb,int balacc,double withmax,double transmax)
        {
            PinNum = passw;
            AccNum = accnumb;
            AccBal = balacc;
            maxWithd = withmax;
            maxTrans = transmax;
            

        }
      

        public override string ToString()
        {
            return AccNum + " " + AccNum + AccBal;
        }
        
    }
      

}


AND THIS IS CHEQUING
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ATM
{
   
    class Chequing : Account
       
  {

        private string maximumBillamount { get; set; }
       private const double billFee = 1.25;
       
//*********************************************************************************************************************************
      /* public void Add(Chequing allaccounts)
     
       {   
           List.add(allaccounts);
        }
       //**********************************************************************************************
         public Chequing()
        {


         }
       //***********************************************************************************88
        public  Chequing this[int accountIndex]
        {
            get
            {
                return (Chequing)list.add[accountIndex];
            }
            set
            {
                list.add[accountIndex] = value;
            }
        }*/
        private bool PayBill()
        {
            
        }
        public Chequing(int PinNumber, int accountNumber, int AccountBalance, int maximumwithdrawal, double maximumtransfer, double interestrate) :

            base(PinNumber, accountNumber, AccountBalance, maximumwithdrawal, maximumtransfer)

{

    this.InterestRate = interestrate;

}


I GET THE ERROR for interest Error 'ATM.Chequing' does not contain a definition for 'InterestRate' and no extension method 'InterestRate' accepting a first argument of type 'ATM.Chequing' could be found (are you missing a using directive or an assembly reference?)

and for paybill()
i know its cause they arent declared ill worry about that later
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2