Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 Depreciation_Calculator
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- comboBoxLife.SelectedIndex = 0;
- radioButtonSLine.Checked = true;
- }
- private void buttonUpdate_Click(object sender, EventArgs e)
- {
- if (double.Parse(textBoxICost.Text) <= double.Parse(textBoxSVal.Text))
- MessageBox.Show("Initial Cost must be greater than Salvage Cost");
- else
- {
- double depreciation = 0, bookVal = 0;
- int life = int.Parse(comboBoxLife.GetItemText(comboBoxLife.SelectedItem));
- double asset = double.Parse(textBoxICost.Text);
- double sVal = double.Parse(textBoxSVal.Text);
- listBoxOutput.Items.Clear(); // clear ouput
- if (radioButtonSLine.Checked)
- {
- depreciation = SLN(asset, sVal, life);
- bookVal = asset;
- listBoxOutput.Items.Add("YEAR\t\tDEPRECIATION\t\tBOOK VALUE");
- for (int x = 0; x < life; ++x)
- {
- bookVal -= depreciation;
- listBoxOutput.Items.Add(x + 1 + "\t\t$" + string.Format("{0:F2}", depreciation) + "\t\t\t$" + string.Format("{0:F2}", bookVal) );
- }
- }
- else
- {
- int y = life;
- bookVal = asset;
- listBoxOutput.Items.Add("YEAR\t\tDEPRECIATION\t\tBOOK VALUE");
- for (int x = 0; x < life; ++x)
- {
- depreciation = (asset - sVal) * (y / SYD(life));
- bookVal = bookVal - depreciation;
- listBoxOutput.Items.Add(x + 1 + "\t\t$" + string.Format("{0:F2}", depreciation) + "\t\t\t$" + string.Format("{0:F2}", bookVal) );
- --y;
- }
- }
- }
- }
- private double SLN(double asset, double sVal, int life)
- {
- double depreciation;
- return depreciation = (asset - sVal) / life;
- }
- private double SYD(int life)
- {
- double depreciation;
- return depreciation = life * (life+1) / 2;
- }
- private void buttonExit_Click(object sender, EventArgs e)
- {
- Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement