C
C#7mo ago
Dinny

Generic Interfaces

I am having trouble implementing a method in my class that I derived from my Generic interface using T data type. IComparableType
using System;
using System.IO;

namespace Modeul_11
{
public interface IComparableType<T>
{
public int CompareTo(T other);
}

}
using System;
using System.IO;

namespace Modeul_11
{
public interface IComparableType<T>
{
public int CompareTo(T other);
}

}
Shape
using Modeul_11;
using System;
using System.IO;

namespace Module_11
{

//Abstract class that extends the interface
public abstract class Shape : IComparableType<Shape>
{
public abstract double Area();

public abstract string WhatAmI();

public int CompareTo(Shape other)
{
//if shape1 is less than shape 2, return -1
// if shape 1 is greater than shape 2, return 1
//if shape 1 and shape 2 are equal, return 0
return 1; //FIXME
}


}
}
using Modeul_11;
using System;
using System.IO;

namespace Module_11
{

//Abstract class that extends the interface
public abstract class Shape : IComparableType<Shape>
{
public abstract double Area();

public abstract string WhatAmI();

public int CompareTo(Shape other)
{
//if shape1 is less than shape 2, return -1
// if shape 1 is greater than shape 2, return 1
//if shape 1 and shape 2 are equal, return 0
return 1; //FIXME
}


}
}
10 Replies
Dinny
Dinny7mo ago
NOTE: IK IT LOOKS WEIRD BUT MY PROF CODES THIS WAY, SO DON'T WORRY ABOUT HOW FUNKY SOME THINGS LOOK. HE'S OLD SCHOOL my issue is where the commented "if statements" are in my shape class the example he gave was " if x.CompareTo(y) < 0, return -1" I am unsure how to do that here since there's no data fields
Angius
Angius7mo ago
I guess it's supposed to compare areas? That Area() method I guess serves as some sort of a Java-ism for a getter
Dinny
Dinny7mo ago
omg slay i remember u u helped me out a lot last time ur like super smart yes it is comparing areas
Jimmacle
Jimmacle7mo ago
your professor doesn't know that IComparable<T> already exists? PepeHmmm
Dinny
Dinny7mo ago
heres the instructions he gave
No description
Dinny
Dinny7mo ago
if this will help it's an intro to generic interfaces and T datatypes so im sure he's already aware omg oops wrong class hold ong
Dinny
Dinny7mo ago
No description
Dinny
Dinny7mo ago
this is the instructions for the shape class if this helps
Jimmacle
Jimmacle7mo ago
yeah so you just have to implement CompareTo for Shape
Dinny
Dinny7mo ago
i was able to figure it out tysm !