The Artima Developer Community
Sponsored Link

Java Answers Forum
AAAAHHHH Not working

1 reply on 1 page. Most recent reply: Oct 2, 2002 12:40 PM by Kishori Sharan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
J

Posts: 3
Nickname: highheat
Registered: Oct, 2002

AAAAHHHH Not working Posted: Oct 2, 2002 8:43 AM
Reply to this message Reply
Advertisement
this is what i have so far

public class DataSet
{
public DataSet(int aNum1, int aNum2, int aNum3, int aNum4)
{
Num1 = aNum1;
Num2 = aNum2;
Num3 = aNum3;
Num4 = aNum4;
}
public void addvalue(int x)
{
x=x+1;
}
public int getSUM()
{
SUM = Num1 + Num2 + Num3 + Num4;
return SUM;
}
public double getAVE()
{
double AVE;
AVE = SUM/x;
return AVE;
}
private int Num1;
private int Num2;
private int Num3;
private int Num4;
private int SUM;
private int x;
}

what i need is that x counts how many numbers i input, when i run the program like this it says that the value cannot be divided by 0, how can I fix this?


Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: AAAAHHHH Not working Posted: Oct 2, 2002 12:40 PM
Reply to this message Reply
Your addvalue method is not updating the value of instance variable x as you intended. Therefore, the instance variable x is always zero and that is why you are getting the error. Make the following change in your addvalue method. To refer to instance variable x write this.x. Simply x means your parameter name x for your method addvalue.

public void addvalue(int x)
{
this.x=x+1;
}

Flat View: This topic has 1 reply on 1 page
Topic: help: HTTP method POST is not supported by this URL Previous Topic   Next Topic Topic: question from one student

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use