Advertisement
X4c3

Depreciation Calculator

Jul 9th, 2020
1,251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Depreciation_Calculator
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public Form1()
  16.         {
  17.             InitializeComponent();
  18.             comboBoxLife.SelectedIndex = 0;
  19.             radioButtonSLine.Checked = true;
  20.            
  21.         }
  22.  
  23.         private void buttonUpdate_Click(object sender, EventArgs e)
  24.         {
  25.  
  26.             if (double.Parse(textBoxICost.Text) <= double.Parse(textBoxSVal.Text))
  27.                 MessageBox.Show("Initial Cost must be greater than Salvage Cost");
  28.             else
  29.             {
  30.  
  31.                 double depreciation = 0, bookVal = 0;
  32.                 int life = int.Parse(comboBoxLife.GetItemText(comboBoxLife.SelectedItem));
  33.                 double asset = double.Parse(textBoxICost.Text);
  34.                 double sVal = double.Parse(textBoxSVal.Text);
  35.                 listBoxOutput.Items.Clear(); // clear ouput
  36.  
  37.  
  38.                 if (radioButtonSLine.Checked)
  39.                 {
  40.                     depreciation = SLN(asset, sVal, life);
  41.                     bookVal = asset;
  42.                     listBoxOutput.Items.Add("YEAR\t\tDEPRECIATION\t\tBOOK VALUE");
  43.                     for (int x = 0; x < life; ++x)
  44.                     {
  45.                         bookVal -= depreciation;
  46.  
  47.                         listBoxOutput.Items.Add(x + 1 + "\t\t$" + string.Format("{0:F2}", depreciation)  + "\t\t\t$" + string.Format("{0:F2}", bookVal) );
  48.                     }
  49.                 }
  50.                 else
  51.                 {
  52.                     int y = life;
  53.                     bookVal = asset;
  54.                     listBoxOutput.Items.Add("YEAR\t\tDEPRECIATION\t\tBOOK VALUE");
  55.                     for (int x = 0; x < life; ++x)
  56.                     {
  57.                         depreciation = (asset - sVal) * (y / SYD(life));
  58.                         bookVal = bookVal - depreciation;
  59.                         listBoxOutput.Items.Add(x + 1 + "\t\t$" + string.Format("{0:F2}", depreciation) + "\t\t\t$" + string.Format("{0:F2}", bookVal) );
  60.                         --y;
  61.                     }
  62.  
  63.                 }
  64.             }
  65.  
  66.         }
  67.  
  68.  
  69.         private double SLN(double asset, double sVal, int life)
  70.         {
  71.             double depreciation;
  72.             return depreciation = (asset - sVal) / life;
  73.         }
  74.  
  75.         private double SYD(int life)
  76.         {
  77.             double depreciation;
  78.             return depreciation = life * (life+1) / 2;
  79.         }
  80.  
  81.         private void buttonExit_Click(object sender, EventArgs e)
  82.         {
  83.             Close();
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement