Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Sfida: Metodi | Introduzione alla Programmazione Orientata agli Oggetti (OOP)
C# Oltre le Basi

bookSfida: Metodi

Completa gli spazi vuoti per creare un metodo che calcola l'area di un cerchio e restituisce il valore.

index.cs

index.cs

copy
123456789101112131415161718192021222324252627282930313233
using 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()}"); } }
  1. Il metodo restituisce un valore di tipo double.
  2. Assicurarsi che il metodo utilizzi la parola chiave public.
index.cs

index.cs

copy
123456789101112131415161718192021222324252627282930313233
using 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()}"); } }
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 3. Capitolo 8

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

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

bookSfida: Metodi

Scorri per mostrare il menu

Completa gli spazi vuoti per creare un metodo che calcola l'area di un cerchio e restituisce il valore.

index.cs

index.cs

copy
123456789101112131415161718192021222324252627282930313233
using 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()}"); } }
  1. Il metodo restituisce un valore di tipo double.
  2. Assicurarsi che il metodo utilizzi la parola chiave public.
index.cs

index.cs

copy
123456789101112131415161718192021222324252627282930313233
using 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()}"); } }
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 3. Capitolo 8
some-alt