473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

BigInteger Problem

I am creating a GUI for class and need help with my program. My program takes 2 big integers and adds them together. First how do I declare my 2 Big Integers and then add them together? I have read the API docs , but still need help. Thanks!
Expand|Select|Wrap|Line Numbers
  1. import java.math.BigInteger;
  2. public class Integer  {
  3.     private BigInteger IntegerONE; // both entered as strings from GUI
  4.     private BigInteger IntegerTWO;
  5.  
  6.  
  7.     public Integer() {
  8.  
  9.     }
  10.  
  11.  
  12.     public Integer( BigInteger IntegerONE, BigInteger IntegerTWO){
  13.         this.IntegerONE = IntegerONE;   // I am not sure here?
  14.         this.IntegerTWO = IntegerTWO;
  15.     }
  16.     public BigInteger getIntegerONE(){
  17.         return IntegerONE;
  18.     }
  19.     public BigInteger getIntegerTWO(){
  20.         return IntegerTWO;
  21.     }
  22.  
  23.  public BigInteger add(BigInteger val){
  24.  
  25.       return(val);       // Psuedocode says(this + val)
  26.     }
  27.  
Jul 19 '07 #1
2 2831
JosAH
11,448 Expert 8TB
The design for that class is incorrect: your class isn't an Integer (there already is
a core class named Integer so your class' name is confusing). Your class is a
Two Integer Manipulator (let's call it TIM). All it can do is add two BigIntegers;
BigIntegers know how to add another BigInteger to themselves so you hardly
need any code:

Expand|Select|Wrap|Line Numbers
  1. public class TIM {
  2.    private BigInteger i1;
  3.    private BigInteger i2;
  4.    //
  5.    public TIM() { this(BigInteger.ZERO, BigInteger.ZERO); }
  6.    public TIM(BigInteger i1, BigInteger i2) {
  7.       this.i1= i1;
  8.       this.i2= i2;
  9.    }
  10.    //
  11.    public BigInteger manipulate() { return i1.add(i2); }
  12. }
  13.  
That is all there is to it.

kind regards,

Jos
Jul 19 '07 #2
The design for that class is incorrect: your class isn't an Integer (there already is
a core class named Integer so your class' name is confusing). Your class is a
Two Integer Manipulator (let's call it TIM). All it can do is add two BigIntegers;
BigIntegers know how to add another BigInteger to themselves so you hardly
need any code:

Expand|Select|Wrap|Line Numbers
  1. public class TIM {
  2.    private BigInteger i1;
  3.    private BigInteger i2;
  4.    //
  5.    public TIM() { this(BigInteger.ZERO, BigInteger.ZERO); }
  6.    public TIM(BigInteger i1, BigInteger i2) {
  7.       this.i1= i1;
  8.       this.i2= i2;
  9.    }
  10.    //
  11.    public BigInteger manipulate() { return i1.add(i2); }
  12. }
  13.  
That is all there is to it.

kind regards,

Jos
Thanks you so much!!
Jul 19 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jerry | last post by:
Hi, I am writing a Java Chatroom application that will implement encryption of messages using the RSA algorithm using the BigInteger class. It uses socket connections to exchange messages. I...
0
by: Krzysztof Adamski | last post by:
Hi, Is it possible in jython to map an PyLong object to other class than BigInteger (i.e. java.lang.Long) ? Thanks for you help, Krzysztof Adamski
117
by: Peter Olcott | last post by:
www.halting-problem.com
4
by: adrin | last post by:
I have to create a c++ class similar to BigInteger from java... but i have no idea, how can i implement big numbers at all(mabye store every digit in list element? :)) how is it properly done? ...
0
by: hitler123 | last post by:
can anyone say me how to define BigInteger as a datatype in an xsd. this xsd i am uising in the xmlbeans.
19
by: shana07 | last post by:
I don't understand about this program is doing. Could someone please tell me what it is about. Because I have gcd function in one program that calls this function. Thanks a lot switch (opcode) {...
2
by: jehugaleahsa | last post by:
Hello: I am currently working on a some simple (not really) classes called BigInteger and BigRational. They are pretty much identical to Java's BigInteger and BigDecimal classes, respectfully. ...
6
by: mearvk | last post by:
Does C++ or C have something roughly equivalent to this: http://java.sun.com/javase/6/docs/api/java/math/BigInteger.html What I need is a way to quickly convert between decimal and binary and...
11
by: imranisb | last post by:
Hi, Im developing RSA cryptography based application in VC#.Net 2.0 and need to use "BigInteger.probablePrime()". I know that VC#.Net 2.0 doesn't have the BigInteger class but found that one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.