C# Programma console che calcola il volume di una scatola

Jakub Lemiszewski

Utente Attivo
5 Dic 2013
119
1
0
Salve,
Ho dovuto creare un applicazione in console per il calcolo del volume di una scatola con i decimali.
Ho utilizzato get e set come proprietà nella forma seguente:
Es:
Codice:
class Person
{
    private int age;
    public int Age 
    {
        get
        {
            return age;
        }
        set
        {
            age = value;
        }
    }
}
Il codice non mi da nessun errore ma non mi funziona nel senso che non mi calcola il volume della scatola box.
Vorrei che mi aiutaste a capire quale é il mio errore e mostrarmi una soluzione perché e da molte ore ormai che ci sto sopra e non so propio cosa fare.
Grazie mille.
Codice:
Codice:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Black0605
{
	class Program
	{
		public static void Main (string[] args)
		{
			// Box Obj
			Box b = new Box ();
			// Box Values for the calculation
			b.setLength = 10m;
			b.setWidht = 20m;
			b.setHeight = 30m;
			// Box volume stored here
			decimal volume = 0.0m;
			// Box volume calculation
			volume = b.Volume;
			// Box volume output
			Console.WriteLine ("Box volume is {0}", volume);
		}
	}
	class Box
	{
		// Decimal fields
		private decimal length;
		private decimal widht;
		private decimal height;
		// Volume field
		private decimal volume;
		// Volume method
		public decimal Volume
		{
			get 
			{
				return volume;
			}
			set
			{
				this.volume = setLength * setWidht * setHeight;
			}
		}
		// Lenght method
		public decimal setLength
		{
			get
			{
				return length;
			}
			set
			{
				this.length = setLength;
			}
		}
		// Width method
		public decimal setWidht
		{
			get
			{
				return widht;
			}
			set
			{
				this.widht = setWidht;
			}
		}
		// Height method
		public decimal setHeight
		{
			get
			{
				return height;
			}
			set
			{
				this.height = setHeight;
			}

		}
	}
}
 
Ciao, la sintassi corretta per il get\set è la seguente

Codice:
public decimal setLength
        {
            get
            {
                return length;
            }
            set
            {
                this.length = [B]value[/B];
            }
        }

Per il calcolo del volume ti consiglio di creare un metodo pubblico che ti restituisce il volume in base ai valori impostati.
 
Ultima modifica:

Discussioni simili