0

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.

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by persianprez
0

Hmm... No, I don't think you are on the right track. Do you remember the diagram of number? Something like...

Number
                        |
     +------------------+-----------+
     |                  |           |
     Real            Integer     Imaginary
  /       \             |
rational irrational     |
                     ---+---
                   /    |    \
                neg     0     pos

That's just from the top of my head. I don't think it is completely correct. So what you may need to do is a class of Number that can handle stuff like that... Not sure why it is so complicated... Are you a beginner or somewhat experienced now?

Edited by Taywin: n/a

0

I've been programming for years, but I've only started programming in Java. I think what I'm supposed to do is write different classes for each type of number and then write the methods for each operation.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.