Utfordring: Metoder
Fyll inn de manglende feltene for å lage en metode som beregner arealet av en sirkel og returnerer verdien.
index.cs
123456789101112131415161718192021222324252627282930313233using System; public class ConsoleApp { class Point { public double x; public double y; } class Circle { public double radius; public Point center; ___ ___ ___() { // The formula is: pi . r . r // The value of pi is 3.14 // r is the radius ___ ___ * ___* radius; } } public static void Main(string[] args) { Point p = new Point(); p.x = 15; p.y = 15; Circle circle = new Circle(); circle.radius = 10; circle.center = p; Console.WriteLine($"Area of the circle with center at ({circle.center.x}, {circle.center.y}) and radius of {circle.radius} is {circle.area()}"); } }
- Metoden returnerer en
double
-verdi. - Sørg for at metoden bruker nøkkelordet
public
.
index.cs
123456789101112131415161718192021222324252627282930313233using System; public class ConsoleApp { class Point { public double x; public double y; } class Circle { public double radius; public Point center; public double area() { // The formula is: pi . r . r // The value of pi is 3.14 // r is the radius return 3.14 * radius * radius; } } public static void Main(string[] args) { Point p = new Point(); p.x = 15; p.y = 15; Circle circle = new Circle(); circle.radius = 10; circle.center = p; Console.WriteLine($"Area of the circle with center at ({circle.center.x}, {circle.center.y}) and radius of {circle.radius} is {circle.area()}"); } }
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 3. Kapittel 8
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Awesome!
Completion rate improved to 2.04
Utfordring: Metoder
Sveip for å vise menyen
Fyll inn de manglende feltene for å lage en metode som beregner arealet av en sirkel og returnerer verdien.
index.cs
123456789101112131415161718192021222324252627282930313233using System; public class ConsoleApp { class Point { public double x; public double y; } class Circle { public double radius; public Point center; ___ ___ ___() { // The formula is: pi . r . r // The value of pi is 3.14 // r is the radius ___ ___ * ___* radius; } } public static void Main(string[] args) { Point p = new Point(); p.x = 15; p.y = 15; Circle circle = new Circle(); circle.radius = 10; circle.center = p; Console.WriteLine($"Area of the circle with center at ({circle.center.x}, {circle.center.y}) and radius of {circle.radius} is {circle.area()}"); } }
- Metoden returnerer en
double
-verdi. - Sørg for at metoden bruker nøkkelordet
public
.
index.cs
123456789101112131415161718192021222324252627282930313233using System; public class ConsoleApp { class Point { public double x; public double y; } class Circle { public double radius; public Point center; public double area() { // The formula is: pi . r . r // The value of pi is 3.14 // r is the radius return 3.14 * radius * radius; } } public static void Main(string[] args) { Point p = new Point(); p.x = 15; p.y = 15; Circle circle = new Circle(); circle.radius = 10; circle.center = p; Console.WriteLine($"Area of the circle with center at ({circle.center.x}, {circle.center.y}) and radius of {circle.radius} is {circle.area()}"); } }
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 3. Kapittel 8