In: Computer Science
Demonstrate using the class and its properties/methods in C#.
// do comment if any problem arises
// code
using System;
class Shoe
{
// ForGender – r/w property (legal values: M or F – define a public enum in the class)
public enum gender { M, F };
public gender ForGender;
// Brand – r/w property (string)
public string brand;
// US_ShoeSize – r/w property (decimal).
public double US_ShoeSize;
// UK_ShoeSize – public read-only & private set property.
private double UK_ShoeSize;
// Constructor method that sets the initial Brand, US_ShoeSize, ForGender of the shoe.
Shoe(string brand, double US_ShoeSize, gender ForGender)
{
this.brand = brand;
this.ForGender = ForGender;
// Must be between 2 and 20 (throw an error if not).
if (US_ShoeSize < 2 || US_ShoeSize > 20)
throw new Exception("Invalid Shoe size");
else
this.US_ShoeSize = US_ShoeSize;
// 0.5 smaller than US_Size for men’s shoes, 2.5 smaller for woman’s shoes.
if (ForGender == gender.M)
this.UK_ShoeSize = US_ShoeSize - 0.5;
else
this.UK_ShoeSize = US_ShoeSize - 0.25;
}
public static void Main()
{
// testing
Shoe testing1=new Shoe("abc",10,gender.M);
Shoe testing2=new Shoe("abc",100,gender.M);
}
}
Output: