Dear Dream.In.Code community,
I am trying to learn C# and I'm doing it by myself, with a book in one hand and the other one on the keyboard. So I decided to make a new class, that is a console calculator class( I know I can make it much simpler and I have but I want to try to make it class based, and I need all the functionalities I implemented in the code( and I hope I have done it correctly). Now my problem is that I don't know how to instance my class, or how to make it so it's usable, and if possible with user input parameters( however for now it's optional. I have included the code here:
thanks in advance guys.
I am trying to learn C# and I'm doing it by myself, with a book in one hand and the other one on the keyboard. So I decided to make a new class, that is a console calculator class( I know I can make it much simpler and I have but I want to try to make it class based, and I need all the functionalities I implemented in the code( and I hope I have done it correctly). Now my problem is that I don't know how to instance my class, or how to make it so it's usable, and if possible with user input parameters( however for now it's optional. I have included the code here:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class Calculator
{
public Double operand1;
public Double operand2;
public Double radijuspol;
public Double Radijusprec;
public Double PI = Math.PI;
public Calculator(Double num1, Double num2)
{
this.operand1 = num1;
this.operand2 = num2;
}
public void Broj1()
{
Console.WriteLine(this.operand1);
}
public void Broj2()
{
Console.WriteLine(this.operand2);
}
public void radijus (Double num1)
{
this.radijuspol=num1;
}
public void Radijus (Double num2)
{
this.Radijusprec=num2;
}
public Double Sabiranje()
{
return this.operand1 + this.operand2;
}
public Double Oduzimanje()
{
return this.operand1 - this.operand2;
}
public Double Mnozenje()
{
return this.operand1 * this.operand2;
}
public Double Dijeljenje()
{
return this.operand1 / this.operand2;
}
public static Double Sabiranjestat(Double num1,Double num2)
{
return num1 + num2;
}
public static Double Oduzimanjestat(Double num1, Double num2)
{
return num1 - num2;
}
public static Double Mnozenjestat(Double num1, Double num2)
{
return num1 * num2;
}
public static Double Dijeljenjestat(Double num1, Double num2)
{
return num1 / num2;
}
public static Double Povrsinakrugapoluprecnik(Double num1)
{
return Math.PI * num1 * num1;
}
public static Double Povrsinakrugaprecnik(Double num2)
{
return (Math.PI * num2 * num2) / 4;
}
}
thanks in advance guys.