Guest_imported
New member
- Jan 1, 1970
- 0
Im just getting into "real" OOP, as i have been working with classes in PHP for a while now, so i have a basic knowledge of how things should go, but as some of you know, php isnt a "real" oop, but it has some elements. Anyway lets not go into that. My question is, what should my method structure be like? Can someone just give me some pointers, or whatever, on what i am doing wrong??
Here is one of the sources i have written (dont laugh too hard, i am just learning C#)
Ok, so say i want to take 2 input variables, multiply them together, and get the area and perimeter of a square (this is easy with no oop, and probably with oop too, i just dont get it yet). Ok, so here is what i have.. The syntax is C#, but its almost the same as Java.
using System;
using System.Text.RegularExpressions;
public class DoMath
{
int width;
int height;
int area;
int heightper;
int widthper;
int perim;
public void Width()
{
Console.WriteLine("Please Enter the Width of your Rectangle:"
width = Console.Read();
}
public void Height()
{
Console.WriteLine("Please Enter the Height of your Rectangle:"
height = Console.Read();
}
public void ExecMath(int height, int width)
{
if(height == width){
w = width;
w = height;
} else {
w = width;
h = height;
}
this.area = w * h;
this.perim = w + h;
Console.WriteLine("The Area of your Square is: {0}, and the perimeter is {1}", this.area, this.perim);
}
}
public class GetResults
{
static void Main()
{
DoMath.Width();
DoMath.Height();
DoMath.ExecMath(int height, int width);
}
}
I just have no idea where i am supposed to call what..... Should i read the vars in the methods, or in the Main()?
Here is one of the sources i have written (dont laugh too hard, i am just learning C#)
Ok, so say i want to take 2 input variables, multiply them together, and get the area and perimeter of a square (this is easy with no oop, and probably with oop too, i just dont get it yet). Ok, so here is what i have.. The syntax is C#, but its almost the same as Java.
using System;
using System.Text.RegularExpressions;
public class DoMath
{
int width;
int height;
int area;
int heightper;
int widthper;
int perim;
public void Width()
{
Console.WriteLine("Please Enter the Width of your Rectangle:"
width = Console.Read();
}
public void Height()
{
Console.WriteLine("Please Enter the Height of your Rectangle:"
height = Console.Read();
}
public void ExecMath(int height, int width)
{
if(height == width){
w = width;
w = height;
} else {
w = width;
h = height;
}
this.area = w * h;
this.perim = w + h;
Console.WriteLine("The Area of your Square is: {0}, and the perimeter is {1}", this.area, this.perim);
}
}
public class GetResults
{
static void Main()
{
DoMath.Width();
DoMath.Height();
DoMath.ExecMath(int height, int width);
}
}
I just have no idea where i am supposed to call what..... Should i read the vars in the methods, or in the Main()?