C
C#13mo 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
DinnyOP13mo 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
Angius13mo 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
DinnyOP13mo ago
omg slay i remember u u helped me out a lot last time ur like super smart yes it is comparing areas
Jimmacle
Jimmacle13mo ago
your professor doesn't know that IComparable<T> already exists? PepeHmmm
Dinny
DinnyOP13mo ago
heres the instructions he gave
No description
Dinny
DinnyOP13mo 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
DinnyOP13mo ago
No description
Dinny
DinnyOP13mo ago
this is the instructions for the shape class if this helps
Jimmacle
Jimmacle13mo ago
yeah so you just have to implement CompareTo for Shape
Dinny
DinnyOP13mo ago
i was able to figure it out tysm !
Want results from more Discord servers?
Add your server