Question

In: Computer Science

Define a class Shoe with the following properties & methods. ForGender – r/w property (legal values:...

  1. Define a class Shoe with the following properties & methods.
  • ForGender – r/w property (legal values: M or F – define a public enum in the class)
  • Brand – r/w property (string)
  • US_ShoeSize – r/w property (decimal). Must be between 2 and 20 (throw an error if not).
  • UK_ShoeSize – public read-only & private set property. 0.5 smaller than US_Size for men’s shoes, 2.5 smaller for woman’s shoes.
  • Constructor method that sets the initial Brand, US_ShoeSize, ForGender of the shoe.

Demonstrate using the class and its properties/methods in C#.

Solutions

Expert Solution

// 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:


Related Solutions

define p values. explain the two methods of interpreting p values
define p values. explain the two methods of interpreting p values
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in Java. Circle Circle Radius: double Circle() Circle(newRadius: double) getArea(): double setRadius(newRadius: double): void getRadius(): double After creating the Circle class, you should test this class from the main() method by passing objects of this class to a method “ public static void printAreas(Circle c, int times)” You should display the area of the circle object 5 times with different radii.
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in...
1: (Passing Objects to Methods) From the following UML Class Diagram, define the Circle class in Java. Circle Circle Radius: double Circle() Circle(newRadius: double) getArea(): double setRadius(newRadius: double): void getRadius(): double After creating the Circle class, you should test this class from the main() method by passing objects of this class to a method “ public static void printAreas(Circle c, int times)” You should display the area of the circle object 5 times with different radii.
You are asked to implement a class Pizza, the default values of properties are given as:...
You are asked to implement a class Pizza, the default values of properties are given as: Diameter: 8.0 Name: DefaultName Supplier: DefaultSupplier Hints: A pizza with diameter greater than 15 will be considered as a large pizza. The method IsLargePizza will return a true if the pizza is considered as a large pizza or a false if it is not considered as a large pizza. There are two ToString methods, the one with no parameter passed will return the information...
c++ programming 1.1 Class definition Define a class bankAccount to implement the basic properties of a...
c++ programming 1.1 Class definition Define a class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data:  Account holder’s name (string)  Account number (int)  Account type (string, check/savings/business)  Balance (double)  Interest rate (double) – store interest rate as a decimal number.  Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. 1.2 Implement...
// **************************************************************** // Incrementarray.java // // Define a IncrementMatrix class with methods to create and read...
// **************************************************************** // Incrementarray.java // // Define a IncrementMatrix class with methods to create and read in // info for a matrix and to check whether the matrix (2d array) is increment, // in other words, all elements in each row are in increasing order and // all elements in each column are in increasing order. // **************************************************************** import java.util.Scanner; public class IncrementMatrix { int[][] matrix; //-------------------------------------- //create new array of given size //-------------------------------------- public IncrementMatrix(int row, int col) {...
Define empty methods in Queue class using LinkedList class in Java ------------------------------------------------------------------------------- //Queue class public class...
Define empty methods in Queue class using LinkedList class in Java ------------------------------------------------------------------------------- //Queue class public class Queue{ public Queue(){ // use the linked list } public void enqueue(int item){ // add item to end of queue } public int dequeue(){ // remove & return item from the front of the queue } public int peek(){ // return item from front of queue without removing it } public boolean isEmpty(){ // return true if the Queue is empty, otherwise false }...
Define empty methods in Stack class using LinkedList class in Java ------------------------------------------------------------------------------- //Stack class public class...
Define empty methods in Stack class using LinkedList class in Java ------------------------------------------------------------------------------- //Stack class public class Stack{ public Stack(){ // use LinkedList class } public void push(int item){ // push item to stack } public int pop(){ // remove & return top item in Stack } public int peek(){ // return top item in Stack without removing it } public boolean isEmpty(){ // return true if the Stack is empty, otherwise false } public int getElementCount(){ // return current number...
In C++, define the class bankAccount to implement the basic properties of a bank account. An...
In C++, define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 components of type bankAccount to...
Which of the following properties are excepted property in regards to the special depreciation allowance? Property...
Which of the following properties are excepted property in regards to the special depreciation allowance? Property placed into service and disposed of in the next tax year. Property converted from personal use to business use in the same or later tax year. Property on which the taxpayer uses the Alternative Depreciation System. Listed property used 50% or less for business.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT