now, for example, the user enters 28. this is what the program will show:

Enter a number:

28

1 DEFICIENT

2 DEFICIENT

3 DEFICIENT

4 DEFICIENT

5 DEFICIENT

6 PERFECT

7 DEFICIENT

8 DEFICIENT

9 DEFICIENT

10 DEFICIENT

11 DEFICIENT

12 ABUNDANT

13 DEFICIENT

14 DEFICIENT

15 DEFICIENT

16 DEFICIENT

17 DEFICIENT

18 ABUNDANT

19 DEFICIENT

20 ABUNDANT

21 DEFICIENT

22 DEFICIENT

23 DEFICIENT

24 ABUNDANT

25 DEFICIENT

26 DEFICIENT

27 DEFICIENT

28 PERFECT

Press any key to continue...

i need then a percentage of how many perfect numbers i have, how many abundant and how many deficients.

i dont know how to do something like that, any ideas?

Inroduce a variable to keep track of how many of each type you have (in pseudo-code)and you said something about count them, i dont know what u mean by that.

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter

Originally posted by apollo abel:

perfectCount++,

it stores the numbers that are perfect,

so perfectCount/total*100

is total the number of all the numbers, including, perfect, abundant amd deficient??

No that is the percentage of perfect numbers. total, not surprisingly is the total of perfect, abundant and deficient numbers.

perfectCount/total == ratio of perfect numbers to the total, a decimal value is returned that is 0<=x<=1. The *100 just puts the value in standard percentage.

If you have 10 perfect, out of 25, that is 10/25*100=.4*100=40%. Of course the % is not automatically added to the resulting value.

[ April 09, 2006: Message edited by: Rusty Shackleford ]

"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra

F:\Codes\NumPADTester.java:27: unexpected type

required: variable

found : value

howdy.getPerfectCount()++;

^

F:\Codes\NumPADTester.java:32: unexpected type

required: variable

found : value

howdy.getAbundantCount()++;

^

F:\Codes\NumPADTester.java:37: unexpected type

required: variable

found : value

howdy.getDeficientCount()++;

what i tried to do was, i created some variables in the main class with the get methods:

and then i used them in the test class, however, i get the errors above mentioned, would you guys give me a clue as to why are im getting the errors??

thanks for the support.

[ April 09, 2006: Message edited by: apollo abel ]

You are asking howdy for an value and then trying to increment it, the problem is there is no variable to place the value in, hence the complaints from the compiler.

You might try adding set methods in NumPad and incrementing there, instead of in main. The NumPad functionality should be in NumPad. Then you can retrieve them and manipulate them at the end.

[ April 09, 2006: Message edited by: Rusty Shackleford ]

"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra

Originally posted by Rusty Shackleford:

howdy.getPerfectCount()++

You are asking howdy for an value and then trying to increment it, the problem is there is no variable to place the value in, hence the complaints from the compiler.

You might try adding set methods in NumPad and incrementing there, instead of in main. The NumPad functionality should be in NumPad. Then you can retrieve them and manipulate them at the end.

[ April 09, 2006: Message edited by: Rusty Shackleford ]

I've been trying and trying to move:

to the NumPAD class, however, it does not work, howdy.getPerfectCount()++; was my only hope, is there any other way around this?

the errors show:

F:\Codes\NumPADTester.java:27: unexpected type

required: variable

found : value

howdy.getPerfectCount()++;

^

F:\Codes\NumPADTester.java:32: unexpected type

required: variable

found : value

howdy.getAbundantCount()++;

^

F:\Codes\NumPADTester.java:37: unexpected type

required: variable

found : value

howdy.getDeficientCount()++;

they point at the "()", if i add something there would it work?

What I meant was:

in NumPad:

public void setPerfectCount()

{

perfectCount++;

}

Then instead of this ugly line, howdy.getPerfectCount()++, just use howdy.setPerfectCount();

Then when you are ready to make the calculations, just call getPerfectCount(). You can even add methods that calculates and returns all the values in NumPad if you like. Here is one possibility:

public int getTotalCount()

{

return perfectCount+abunduntCount+deficientCount;

}

If you insist on doing it the way you had it, you still need a variable so howdy.getPerfectCount()++ has something to place the value in.

perfectCount=howdy.getPerfectCount()++;

No, do not pass values to getPerfectCount(), it accepts no parameters and passing anything will result in more errors.

"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra

Originally posted by Rusty Shackleford:

You do not need to move all that to NumPad, and you should not.

What I meant was:

in NumPad:

public void setPerfectCount()

{

perfectCount++;

}

Then instead of this ugly line, howdy.getPerfectCount()++, just use howdy.setPerfectCount();

Then when you are ready to make the calculations, just call getPerfectCount(). You can even add methods that calculates and returns all the values in NumPad if you like. Here is one possibility:

public int getTotalCount()

{

return perfectCount+abunduntCount+deficientCount;

}

If you insist on doing it the way you had it, you still need a variable so howdy.getPerfectCount()++ has something to place the value in.

perfectCount=howdy.getPerfectCount()++;

No, do not pass values to getPerfectCount(), it accepts no parameters and passing anything will result in more errors.

Oh i see what you mean, well i can say i've learned something today, i'd go ahead and give it a try

the result i got:

Enter a number:

28

1 DEFICIENT

2 DEFICIENT

3 DEFICIENT

4 DEFICIENT

5 DEFICIENT

6 PERFECT

7 DEFICIENT

8 DEFICIENT

9 DEFICIENT

10 DEFICIENT

11 DEFICIENT

12 ABUNDANT

13 DEFICIENT

14 DEFICIENT

15 DEFICIENT

16 DEFICIENT

17 DEFICIENT

18 ABUNDANT

19 DEFICIENT

20 ABUNDANT

21 DEFICIENT

22 DEFICIENT

23 DEFICIENT

24 ABUNDANT

25 DEFICIENT

26 DEFICIENT

27 DEFICIENT

28 PERFECT

The percentage of perfect numbers is: 7.142857142857142

The percentage of abundant numbers is: 14.285714285714285

The percentage of deficient numbers is: 78.57142857142857

Press any key to continue...

Looks about right, doesnt it?

Oh and thanks alot for the support, you guys are the best

[ April 09, 2006: Message edited by: apollo abel ]

It is sorta covered in the JavaRanch Style Guide. |