# Perfect/Deficient/Abundant Nums problem

• 04-14-2010, 03:49 PM
killertofu
Perfect/Deficient/Abundant Nums problem
Hey everyone, I'm working on a program for a class that allows me to determine whether a number is perfect, deficient or abundant. I have the core of it, but I keep getting some strange errors. My professor is pretty useless when it comes to explaining things, so I was hoping someone here could help me.

The only error (i think) is now showing up at line 40 at the public class perfectnums{ line.
It says:
Multiple markers at this line
- The nested type perfectnums cannot hide an enclosing type
- Syntax error, insert "ClassBody" to complete ClassDeclaration

I'm confused by this... Thanks in advance!

Code:

```import java.util.*; public class perfectnums {         /**         * @param args         */         //list of instance variables                 private int sum;                 private int num;                 private double numPerfect;                 private double numAbundant;                 private double numDeficient;                 private double total;                 private String name;                 Scanner input = new Scanner(System.in);                 String exit = "1";                                 public perfectnums(int num, String name)                 {                         this.num = num;                         this.name = name;                 }                                 public int sumFactors(int num)                 {                         sum = 0;                         for(int i =        1; i <= num/2; i++)                         {                                 if(num % i ==0)                                 {                                         sum = sum + i;                                 }                         }                         return sum;                 }                 //public static void main(String[] args) {                 //perfectnums digits = new perfectnums(num,name);                 public class perfectnums{                                 for(int i = 1; i <= num; i++)                 {                           System.out.print(i);                                                   if (i == perfectnums.sumFactors(i))                           {                             System.out.println("Perfect");                             perfectnums.setNumPerfect();                           }                                                     else if(i < perfectnums.sumFactors(i))                           {                             System.out.println("Abundant");                             perfectnums.setNumAbundant();                           }                           else                           {                                   System.out.println("Deficient");                                   perfectnums.setNumDeficient();                           }                                     }         }```
• 04-14-2010, 04:55 PM
Eranga
You've define two same class definition in your code, in public.
• 04-14-2010, 05:06 PM
killertofu
So, what would I need to do to erase the problem? I've tried making the public class perfectnums private and some other things like that, but then I get more errors.
• 04-14-2010, 06:10 PM
iluxa
Look at your inner class definition:
Code:

```public class perfectnums{   for(int i = 1; i <= num; i++){   // ...   } }```
no offense, but what is the for-loop doing inside a class definition and not inside some method?
• 04-14-2010, 07:47 PM
Eranga
Quote:

Originally Posted by killertofu
So, what would I need to do to erase the problem? I've tried making the public class perfectnums private and some other things like that, but then I get more errors.

Means that you don't have an idea about the inner class. Think about that lol, without a method how can you define a simple code segment in a class?