Sudoku Java Class

Exception in thread "main" java.lang.NoSuchMethodError: main d

Page 1 of 1

7 Replies - 5352 Views - Last Post: 05 April 2010 - 04:17 PM Rate Topic: -----

#1 wellDAMN  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 05-November 09

Sudoku Java Class

Posted 04 April 2010 - 09:09 PM

When I try to run the program I get this error:
Exception in thread "main" java.lang.NoSuchMethodError: main dreamincode

I know the solution is simple I just cant seem to figure it out. :helpsmilie:
All help is greatly appreciated.

import java.util.Scanner;

public class atmetoyer_SudokuChecker
{
  
    Scanner band = new Scanner (System.in);
        private int w1;
        private int w2;
        private int w3;
        private int w4;
        private int x1;
        private int x2;
        private int x3;
        private int x4;
        private int y1;
        private int y2;
        private int y3;
        private int y4;
        private int z1;
        private int z2;
        private int z3;
        private int z4;

        public atmetoyer_SudokuChecker()
        {
            System.out.println ("Welcome to the Sudoku Checker v1.0! This program checks 4x4 Sudoku grids. Use numbers 1-4 once. Seperate numbers with spaces and to end row hit ENTER.");
        }
        
        public void getGrid ()
        {
            System.out.println();
            System.out.print ("Enter Row 1: ");
            w1 = band.nextInt();
            w2 = band.nextInt();
            w3 = band.nextInt();
            w4 = band.nextInt();
       
            System.out.print ("Enter Row 2: ");
            x1 = band.nextInt();  
            x2 = band.nextInt();
            x3 = band.nextInt();
            x4 = band.nextInt();

            System.out.print ("Enter Row 3: ");
            y1 = band.nextInt();
            y2 = band.nextInt();
            y3 = band.nextInt();
            y4 = band.nextInt();

            System.out.print ("Enter Row 4: ");
            z1 = band.nextInt();
            z2 = band.nextInt();
            z3 = band.nextInt();
            z4 = band.nextInt();
        }
        public void checkGrid ()
        {
            int var = 0;
            System.out.println(); // Region
        
            if ( w1 + w2 + x1 + x2 == 10)
            {
               System.out.println ("REG-1:GOOD");
            }
            else 
            {
                System.out.println ("REG-1:BAD");
                var = var + 1;
            }

            if ( y1 + y2 + z1 + z2 == 10)
            {
               System.out.println ("REG-2:GOOD");
            }
            else
            {
               System.out.println ("REG-2:BAD");
               var = var + 1;
              }

            if ( w3 + w4 + x3 + x4 == 10)
            {
               System.out.println ("REG-3:GOOD");
            }
            else
            {
               System.out.println ("REG-3:BAD");
               var = var + 1;
            }
         
            if ( y3 + y4 + z3 + z4 == 10)
            {
               System.out.println ("REG-4:GOOD");
            }
            else
            {
               System.out.println ("REG-4:BAD");
               var = var + 1;
            }

           System.out.println(); // Row

           if ( w1 + w2 + w3 + w4 == 10)
           {
               System.out.println ("ROW-1:GOOD");
           }
           else
           {
               System.out.println ("ROW-1:BAD")
               var = var + 1;
           }     

           if ( x1 + x2 + x3 + x4 == 10)
           {
               System.out.println ("ROW-2:GOOD");
           }
           else
           {
               System.out.println ("ROW-2:BAD");
               var = var + 1;
           }

           if ( y1 + y2 + y3 + y4 == 10)
           {
               System.out.println ("ROW-3:GOOD");
           }
           else
           {
               System.out.println ("ROW-3:BAD");
               var = var + 1;
           }

           if ( z1 + z2 + z3 + z4 == 10)
           {
               System.out.println ("ROW-4:GOOD");
           }
           else
           {
               System.out.println ("ROW-4:BAD");
               var = var + 1;
           }
  
           System.out.println(); // Coloumn
   
           if ( w1 + x1 + y1 + z1 == 10)
           {
               System.out.println ("COL-1:GOOD");
           }
           else
           {
               System.out.println ("COL-1:BAD");
               var = var + 1;
           }

           if ( w2 + x2 + y2 + z2 == 10)
           {
               System.out.println ("COL-2:GOOD");
           }
           else
           {
               System.out.println ("COL-2:BAD");
               var = var + 1;
           }

           if ( w3 + x3 + y3 + z3 == 10)
           {
               System.out.println ("COL-3:GOOD");
           }
           else
           {
               System.out.println ("COL-3:BAD");
               var = var + 1;
           }

           if ( w4 + x4 + y4 + z4 == 10)
           {
               System.out.println ("COL-4:GOOD");
           }
           else
           {
               System.out.println ("COL-4:BAD");
               var = var + 1;
           }

           System.out.println(); // Flag

           if ( var == 0)
           {
               System.out.println ("SUDO:VALID");
           }
           else
           {
             System.out.println ("SUDO:INVALID");
           }
           System.out.println();
        }
  
}      


    



public class atmetoyer_SudokuCheckerTest
{
    public static void main ( String args[] )
    {
        atmetoyer_SudokuChecker foo = new atmetoyer_SudokuChecker();
        foo.getGrid();
        foo.checkGrid();
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Sudoku Java Class

#2 NoobProgramer  Icon User is offline

  • D.I.C Head

Reputation: -5
  • View blog
  • Posts: 191
  • Joined: 15-June 09

Re: Sudoku Java Class

Posted 04 April 2010 - 10:02 PM

Try this code
instead that
just a simple edit.

import java.util.Scanner;

public class Suduko
{

    Scanner band = new Scanner (System.in);
        private int w1;
        private int w2;
        private int w3;
        private int w4;
        private int x1;
        private int x2;
        private int x3;
        private int x4;
        private int y1;
        private int y2;
        private int y3;
        private int y4;
        private int z1;
        private int z2;
        private int z3;
        private int z4;

        public  Suduko()
        {
            System.out.println ("Welcome to the Sudoku Checker v1.0! This program checks 4x4 Sudoku grids. Use numbers 1-4 once. Seperate numbers with spaces and to end row hit ENTER.");
        }

        public void getGrid ()
        {
            System.out.println();
            System.out.print ("Enter Row 1: ");
            w1 = band.nextInt();
            w2 = band.nextInt();
            w3 = band.nextInt();
            w4 = band.nextInt();

            System.out.print ("Enter Row 2: ");
            x1 = band.nextInt();
            x2 = band.nextInt();
            x3 = band.nextInt();
            x4 = band.nextInt();

            System.out.print ("Enter Row 3: ");
            y1 = band.nextInt();
            y2 = band.nextInt();
            y3 = band.nextInt();
            y4 = band.nextInt();

            System.out.print ("Enter Row 4: ");
            z1 = band.nextInt();
            z2 = band.nextInt();
            z3 = band.nextInt();
            z4 = band.nextInt();
        }
        public void checkGrid ()
        {
            int var = 0;
            System.out.println(); // Region

            if ( w1 + w2 + x1 + x2 == 10)
            {
               System.out.println ("REG-1:GOOD");
            }
            else
            {
                System.out.println ("REG-1:BAD");
                var = var + 1;
            }

            if ( y1 + y2 + z1 + z2 == 10)
            {
               System.out.println ("REG-2:GOOD");
            }
            else
            {
               System.out.println ("REG-2:BAD");
               var = var + 1;
              }

            if ( w3 + w4 + x3 + x4 == 10)
            {
               System.out.println ("REG-3:GOOD");
            }
            else
            {
               System.out.println ("REG-3:BAD");
               var = var + 1;
            }

            if ( y3 + y4 + z3 + z4 == 10)
            {
               System.out.println ("REG-4:GOOD");
            }
            else
            {
               System.out.println ("REG-4:BAD");
               var = var + 1;
            }

           System.out.println(); // Row

           if ( w1 + w2 + w3 + w4 == 10)
           {
               System.out.println ("ROW-1:GOOD");
           }
           else
           {
               System.out.println ("ROW-1:BAD");
               var = var + 1;
           }

           if ( x1 + x2 + x3 + x4 == 10)
           {
               System.out.println ("ROW-2:GOOD");
           }
           else
           {
               System.out.println ("ROW-2:BAD");
               var = var + 1;
           }

           if ( y1 + y2 + y3 + y4 == 10)
           {
               System.out.println ("ROW-3:GOOD");
           }
           else
           {
               System.out.println ("ROW-3:BAD");
               var = var + 1;
           }

           if ( z1 + z2 + z3 + z4 == 10)
           {
               System.out.println ("ROW-4:GOOD");
           }
           else
           {
               System.out.println ("ROW-4:BAD");
               var = var + 1;
           }

           System.out.println(); // Coloumn

           if ( w1 + x1 + y1 + z1 == 10)
           {
               System.out.println ("COL-1:GOOD");
           }
           else
           {
               System.out.println ("COL-1:BAD");
               var = var + 1;
           }

           if ( w2 + x2 + y2 + z2 == 10)
           {
               System.out.println ("COL-2:GOOD");
           }
           else
           {
               System.out.println ("COL-2:BAD");
               var = var + 1;
           }

           if ( w3 + x3 + y3 + z3 == 10)
           {
               System.out.println ("COL-3:GOOD");
           }
           else
           {
               System.out.println ("COL-3:BAD");
               var = var + 1;
           }

           if ( w4 + x4 + y4 + z4 == 10)
           {
               System.out.println ("COL-4:GOOD");
           }
           else
           {
               System.out.println ("COL-4:BAD");
               var = var + 1;
           }

           System.out.println(); // Flag

           if ( var == 0)
           {
               System.out.println ("SUDO:VALID");
           }
           else
           {
             System.out.println ("SUDO:INVALID");
           }
           System.out.println();
        }

    public static void main ( String args[] )
    {
        Suduko foo = new Suduko();
        foo.getGrid();
        foo.checkGrid();
    }


  
}





tell me if i helped you.
Was This Post Helpful? 0
  • +
  • -

#3 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2874
  • View blog
  • Posts: 11,032
  • Joined: 15-July 08

Re: Sudoku Java Class

Posted 05 April 2010 - 03:28 AM

@NoobProgramer, that is not necessary.

@OP, since atmetoyer_SudokuChecker is not your main method, you need to run atmetoyer_SudokuCheckerTest.

This post has been edited by Dogstopper: 05 April 2010 - 03:05 PM
Reason for edit:: Fixed member tag

Was This Post Helpful? 0
  • +
  • -

#4 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5846
  • View blog
  • Posts: 12,705
  • Joined: 16-October 07

Re: Sudoku Java Class

Posted 05 April 2010 - 04:52 AM

Looks like it should run... Great crap, man! Use an array!

Also, your logic is flawed. If I enter 3,3,2,2 for a row, I still pass. I shouldn't.
Was This Post Helpful? 1
  • +
  • -

#5 wellDAMN  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 05-November 09

Re: Sudoku Java Class

Posted 05 April 2010 - 05:07 AM

Dogstopper thank you I new I was doing something stupid.

baavagi, I had the code written before I was able to use arrays, so it was just copy and paste.
Was This Post Helpful? 0
  • +
  • -

#6 m-e-g-a-z  Icon User is offline

  • Winning
  • member icon


Reputation: 496
  • View blog
  • Posts: 1,453
  • Joined: 19-October 09

Re: Sudoku Java Class

Posted 05 April 2010 - 07:16 AM

Use a for loop for checking, they were created to help us make repetitive tasks easier so why not use them? Loads of If statements aren't nessesary.
Was This Post Helpful? 0
  • +
  • -

#7 wellDAMN  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 56
  • Joined: 05-November 09

Re: Sudoku Java Class

Posted 05 April 2010 - 03:38 PM

This is a homework assignment that was based off of a previous assignment when we were only allowed to use if/else. I see no point in rewriting a new code if I already have the same code only a little longer.

Thanks for the help everyone
Was This Post Helpful? 0
  • +
  • -

#8 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5846
  • View blog
  • Posts: 12,705
  • Joined: 16-October 07

Re: Sudoku Java Class

Posted 05 April 2010 - 04:17 PM

View PostwellDAMN, on 05 April 2010 - 04:38 PM, said:

I see no point in rewriting a new code if I already have the same code only a little longer.


Wow. What an amazingly miserable attitude.

You did not address the fact your validation checker is simply wrong. Cleaning up the code would make solving this easier. If you are unwilling to rewrite code, you are ultimately doomed to failure. Good luck with that.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1