So this is my assignment: Represent the concept of a Number. For this example a Number is a thing that can be added subtracted, multiplied and divided. Each of these operations is binary and produces a Number as a result. Encode the the Notion of of an Int (an integer object), a rational, and a floating point number in terms of the the Number concept.
I have no idea if I am headed in the right direction since there isnt much about this in the text book.
Here is my code so far:
import java.util.Random;
public class IntObj extends java.lang.Object implements java.io.Serializable{
public static void main (String[] args){
Random generator = new Random();
Integer a = new Integer(generator.nextInt(200)+1);
Integer b = new Integer(generator.nextInt(200)+1);
Float c = new Float(generator.nextFloat());
Float d = new Float(generator.nextFloat());
//IntObjs
System.out.println("Addition of " + a + " and " + b+" = "+ (a+b));
System.out.println("Subtraction of " + a + " and " + b+" = "+ (a-b));
System.out.println("Multiplication of " + a + " and " + b+" = "+ (a*b));
System.out.println("Division of " + a + " and " + b+" = "+ (a/b)+"."+(a%b));
System.out.println();
//FloatObjs
System.out.println("Addition of " + c + " and " + d+" = "+ (c+d));
System.out.println("Subtraction of " + c + " and " + d+" = "+ (c-d));
System.out.println("Multiplication of " + c + " and " + d+" = "+ (c*d));
System.out.println("Division of " + c + " and " + d+" = "+ (c/d));
System.out.println();
}
}
I don't even think I'm doing what he is asking. He isn't replying to my emails so any help is appreciated.