java - Trying to use abstract data types - How to call the methods through inheritence -
i trying test abstract class running problems when call methods test class. has been while since used java , have not used abstract classes before. pointers on going wrong appreciated. thanks.
the abstract class
public abstract class rationalnumbers { public int numerator, denominator, temp; public void setnumerator(int n) { numerator = n; } public void setdenominator(int d) { denominator = d; } public int getnumerator() { return numerator; } public int getdenominator() { return denominator; } public int add() { temp = numerator + denominator; return temp; } public int subtract() { temp = numerator - denominator; return temp; } public int multiply() { temp = numerator * denominator; return temp; } public int divide() { temp = numerator / denominator; return temp; } public boolean isequal() { boolean isequal; if (numerator == denominator) { isequal = true; } else { isequal = false; } return isequal; } }
the test class
public class testclass extends rationalnumbers { public static void main(string[] args) { setnumerator(5); setdenominator(10); system.out.println("equal: " + isequal()); system.out.println("numerator: " + getnumerator()); // etc... } }
i'm sorry tell this, attempt @ creating abstraction rational number wrong in every way. not correct at all. none of methods correct: add, subtract, multiply, divide, isequal - utterly incorrect.
wouldn't want override equals()
- and hashcode()
? made think isequal()
idea?
look @ this example of how properly.
Comments
Post a Comment