1 Replies - 1842 Views - Last Post: 21 February 2013 - 07:17 AM Rate Topic: -----

#1 Jimmy1734   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-February 13

Need help, can't figure out code. Money Transfer Project

Posted 21 February 2013 - 01:26 AM

Hi, so I'm having trouble with my coding. I've already figured out how to take money from the class values "Tom" and "Rob", but I can't figure out how to deposit that value into the bank. here's what i have so far.
I would really appreciate it if someone would take a look. Each button takes entered amount from related person and transfers it back to the bank which is what i can't figure out.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab05_E00995877
{
    class Person
    {
        public string Name;
        public decimal Cash;
      
        public decimal ReceiveCash(decimal amount)
        {
            if (amount > 0)
            {
       //      person       money punched in   
                Cash -= amount;
                return Cash;
            }
            else
            {
                MessageBox.Show(amount + "  isnt an amount I'll take",
                    Name + " says..");
                return 0;
            }
        }
    }
}





using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lab05_E00995877
{
    public partial class Form1 : Form
    {
        //Add your form1 variables
        Person Tom;
        Person Rob;
        decimal bank = 50M;

        public Form1()
        {
            InitializeComponent();
            //Initialize (create) Tom and Rob
            Tom = new Person();
            Tom.Name = "Joe";
            Tom.Cash = 150M;
            btnGetOne.Text = "Get from " + Tom.Name;


            Rob = new Person();
            Rob.Name = "Bob";
            Rob.Cash = 200M;
            btnGetTwo.Text = "Get from " + Rob.Name;

            UpdateForm();
        }

        public void UpdateForm()
        {
            lblFirstName.Text = Tom.Name;
            lblMoneyOne.Text = Tom.Cash.ToString();

            lblSecondName.Text = Rob.Name;
            lblMoneyTwo.Text = Rob.Cash.ToString();

            lblMoneyBank.Text = bank.ToString();
        }

        private void btnGetOne_Click(object sender, EventArgs e)
        {
            decimal decAmount, decTomAmount, decRobAmount, decBankAmount;
            try
            {
                decAmount = Decimal.Parse(txtMoney.Text);
                decTomAmount = Decimal.Parse(lblMoneyOne.Text);
                decRobAmount = Decimal.Parse(lblMoneyTwo.Text);
                decBankAmount = Decimal.Parse(lblMoneyBank.Text);
                //bankamount (bank)   Amount punched in (decAmount)
                if (decTomAmount >= decAmount)
                {
                    decBankAmount -= decAmount;
           
                    lblMoneyOne.Text = Tom.ReceiveCash(decAmount).ToString();
                    lblMoneyBank.Text = bank.ToString();

                    
                     //What do i put here to add to bank after subtracting from Tom?
                    
                    
                    UpdateForm();

                }
                else
                {
                    MessageBox.Show("Tom doesnt have this many!");
                }
                txtMoney.Clear();
                txtMoney.Focus();
            }
            catch
            {
                MessageBox.Show("Please enter numbers only!");
                txtMoney.Clear();
                txtMoney.Focus();
            }
        }
        
        private void btnGetTwo_Click(object sender, EventArgs e)
        {

            decimal decAmount, decTomAmount, decRobAmount;
            try
            {
                decAmount = Decimal.Parse(txtMoney.Text);
                decTomAmount = Decimal.Parse(lblMoneyOne.Text);
                decRobAmount = Decimal.Parse(lblMoneyTwo.Text);
                //bankamount (bank)   Amount punched in (decAmount)
                if (decRobAmount >= decAmount)
                {
                    decRobAmount -= decAmount;
                    lblMoneyTwo.Text = Rob.ReceiveCash(decAmount).ToString();
                    lblMoneyBank.Text = bank.ToString();

                    //What do i put here to add to bank after subtracting from Rob?
                    
                    
                    UpdateForm();

                }
                else
                {
                    MessageBox.Show("Rob doesnt have this many!");
                }
                txtMoney.Clear();
                txtMoney.Focus();
            }
            catch
            {
                MessageBox.Show("Please enter numbers only!");
                txtMoney.Clear();
                txtMoney.Focus();
            }
        }
        }
}


Is This A Good Question/Topic? 0
  • +

Replies To: Need help, can't figure out code. Money Transfer Project

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Need help, can't figure out code. Money Transfer Project

Posted 21 February 2013 - 07:17 AM

This is a really common homework assignment. As such we can't provide working code.

"I can't figure it out" is something you need to take to your professor.

There are numerous threads here for banking/ATM homework. Reading a few of them might give you some paths you wouldn't have thought of. There is also a tutorials on classes in my signature block. Perhaps having a clearer idea of classes might help.

But for your specific issue of "I can't figure it out" we simply can't just give you the solution because figuring it out *is* part of the homework.

This post has been edited by tlhIn`toq: 21 February 2013 - 07:18 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1