Desafio: Métodos
Preencha as lacunas para criar um método que calcula a área de um círculo e retorna o valor.
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()}"); } }
- O método retorna um valor
double
. - Certifique-se de que o método utiliza a palavra-chave
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()}"); } }
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 3. Capítulo 8
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Suggested prompts:
Can you give me a hint for filling in the blanks?
Can you show me the complete solution for the method?
Can you explain how to calculate the area of a circle?
Awesome!
Completion rate improved to 2.04
Desafio: Métodos
Deslize para mostrar o menu
Preencha as lacunas para criar um método que calcula a área de um círculo e retorna o valor.
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()}"); } }
- O método retorna um valor
double
. - Certifique-se de que o método utiliza a palavra-chave
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()}"); } }
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 3. Capítulo 8