I need help in writing the addition , subtraction etc. method.
eample the add method must add large intergers,
say 2500 + 69587562. each number is entered in the subscript individually.
this is what i have done so far.I created the class,construct ors
public class Example
{
private int[] values;
private int min;
private int max;
Scanner Key= new Scanner(System. in);
public Example()
{
values=20;
min=0;
max=20;
}
public int ReadSize( int size)
{
System.out.prin tln("Enter the size of the array.")
size=key.nextIn t();
for(int min=0; min<size.length ;min ++)
{
values[min]=key.nextInt();
}
}
Oct 19 '06
18 5838
could u wirte a method for me to see what it would look like, doing it the "FAIR method. thanks
could u wirte a method for me to see what it would look like, doing it the "FAIR method. thanks
should look something like this. I have to go for now but you should make the neccessary changes to your code to make this compile and then try to fine tune it to get the correct results. I 'll be in tommorrow morning about 8 hrs from now but others may be able to help you before then - public LargeInteger add(LargeInteger num) {
-
int size = num.getMax() > getMax() ? num.getMax(): getMax();
-
LargeInteger result = new LargeInteger(size + 1);
-
-
for(int i = 0; i < size; i++) {
-
int resultPos = size;
-
int carry = 0;
-
int numPos = num.getMax();
-
int thisPos = number.getMax();
-
int unit = 0;
-
int sum = carry + num.getDigit(numPos) + number.getDigit(thisPos);
-
if(sum > 10) {
-
unit = sum - 10;
-
carry = 1;
-
}
-
else {
-
carry = 0;
-
unit = sum;
-
}
-
result.setDigit(unit, resultPos);
-
resultPos = resultPos - 1;
-
numPos = numPos - 1;
-
thisPos = thisPos - 1;
-
}
-
return result;
-
-
-
-
}
this is what the program look like.
public class Quest
{
public static void main(String []args)
{
example test= new example (5);
example test2= new example(6);
example test3= new example(7);
test.readinfo() ;
test.printnum() ;
test2.readinfo( );
test2.printnum( );
test3.add(test, test2);
this is the class that i have so far. would u kindly help with the addition
subtraction methods. sorry am going to copy and paste this here.
public class example
{
private int [] values;
public example ()
{
values= new int[40];
}
public example(int size)
{
values=new int [size];
}
public void readinfo()
{
int ctr=0;
String asknum=JOptionP ane.showInputDi alog("Enter the numbers.");
for( int i=asknum.length () -1; i >=0; i--)
{
values [ctr]=asknum.charAt( i)-48;
ctr ++;
}
}
public void printnum()
{
for(int i=0; i<values.length ; i ++)
{
JOptionPane.sho wMessageDialog( null,"Display the numbers." + values[i]);
}
}
public void add( )
{
this is what the program look like.
public class Quest
{
public static void main(String []args)
{
example test= new example (5);
example test2= new example(6);
example test3= new example(7);
test.readinfo() ;
test.printnum() ;
test2.readinfo( );
test2.printnum( );
test3.add(test, test2);
this is the class that i have so far. would u kindly help with the addition
subtraction methods. sorry am going to copy and paste this here.
public class example
{
private int [] values;
public example ()
{
values= new int[40];
}
public example(int size)
{
values=new int [size];
}
public void readinfo()
{
int ctr=0;
String asknum=JOptionP ane.showInputDi alog("Enter the numbers.");
for( int i=asknum.length () -1; i >=0; i--)
{
values [ctr]=asknum.charAt( i)-48;
ctr ++;
}
}
public void printnum()
{
for(int i=0; i<values.length ; i ++)
{
JOptionPane.sho wMessageDialog( null,"Display the numbers." + values[i]);
}
}
public void add( )
{
Are we still going the right direction here?
am sorry, but i am.
that is what i came up with for the read statement, now following that i need help in the addition method, note please take a look at the program also.
i need hepl with the addition and subtraction method.above you will see what i did so far.
also how do you declare a class within a class method. example.
the program would be:
example test=new example()
example test2=new example()
example test3=new example()
test.readinfo() ;
test2.readinfo( )
test3(test,test 2) HOW IS THIS REPRESENTED INT THE CLASS METHOD
public void add( WHAT GOES IN HERE)
THANKS FOR HELPING.
Is This Correct.
public void add( examplexx a, examplexx b)
{
int carry=0;
int sum=0;
for(int i=0; i<values.length ; i ++)
{
sum=carry + values.length + values.length;
if( sum >=10)
{
sum= sum-10;
carry =1;
}
else
{
carry =0;
}
}
JOptionPane.sho wMessageDialog( null, "The final sum is . " + sum);
}
Is This Correct.
public void add( examplexx a, examplexx b)
{
int carry=0;
int sum=0;
for(int i=0; i<values.length ; i ++)
{
sum=carry + values.length + values.length;
if( sum >=10)
{
sum= sum-10;
carry =1;
}
else
{
carry =0;
}
}
JOptionPane.sho wMessageDialog( null, "The final sum is . " + sum);
}
All I can say is this depends on where the method is. If the method is the number class (which in this case is examplexx?) then the method signature should be - public examplexx add(examplexx a)
. This is how I think you should be doing it as you could tell for my draft method for add that I did above(If you looked at it).
Now your method is taking in two objects a and b and doing absolutely nothing with them?
Needless for me to point out that values is not defined in your method and so the method will not compile anyway.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: KellyH |
last post by:
Hi, I hope someone can point me in the right direction.
I'll get it out of the way: Yes, I am a college student. No, I am not
looking for anyone to do my homework, just looking for help. I have been
reading this ng all semester, and found it very helpful. I just have a
stupid problem going on right now.
Here's the project:
We have to make a little frame with a text field, where the user inputs a
number, and a text area where a...
|
by: Markus Dehmann |
last post by:
I have n sets of elements. I want to find elements that occur more than once
in more than one set.
Maybe the following example shows what I mean:
S1 = {1,2,3,2,4}
S2 = {2,2,4,5,4}
S2 = {2,5,2}
The algorithm should find that the "2" occurs more than once in S1, S2, and
|
by: akameswaran |
last post by:
Disclaimer - I recognize this is not a practical exercise. There are
many implementations around that would do the job better, more
efficiently (Meaning in C) or whatever.
I caught some thread about sorting and started thinking about shell
sort.... and as part of my trying to pythonise my mind and break my
java mindset
So I decided to tackle this old school problem with the python mindset.
|
by: heddy |
last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int
Newsize); and the newsize is smaller then what the array was
previously, are the resources allocated to the objects that are now
thown out of the array released properly by the CLI?
|
by: broeisi |
last post by:
Hello,
Is there a way in C to get information at runtime if a processor is 32
or 64 bit?
Cheers,
Broeisi
| |
by: ablock |
last post by:
I have an array to which i have a added a method called contains. I
would like to transverse this array using for...in...I understand
fully that for...in is really meant for Objects and not Arrays, but I
purposely had this array filled unsequentially because the key for the
array is meant to act as an ID which has a contextual meaning in my
script.
The problem, of course, is that for...in also returns my method
'contains' as one of the...
|
by: hamishd |
last post by:
What is the best way to store large arrays of numbers (eg, 4-byte
integers)?
Say I want to store an array of 1billion 4-byte integers.. If my
computer has 4gB memory, then is this possible?
int Large_Array;
This will cause a "stack overflow" when i try and execute. How can I
do this?
|
by: JinFTW |
last post by:
Ok so I had to develop a class in which I needed to count the number of times someone enters in a number from a selected group of numbers from 1 to 100. In this case we're talking about groups of 10. Since I'm not very good with arrays (it was advised I use an array of counters, but since my professor has yet to teach us do so, that wouldn't really work anyway). So I decided to get creative and do it this way (not finished yet, only worked up to...
|
by: istillshine |
last post by:
There are many languages around: C++, JAVA, PASCAL, and so on. I
tried to learn C++ and JAVA, but ended up criticizing them. Is it
because C was my first programming language?
I like C because, comparatively, it is small, efficient, and able to
handle large and complex tasks.
I could not understand why people are using and talking about other
programming languages.
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |