#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    1

    Variable Parameter Amount Constructor


    I'm trying to create a program that automates the normalisation process for RDMSs but I've hit a plateau when compiling code that is trying to handle creating objects for a constructor that has yet to be created and will have x amount of parameters. Here is the full source code:

    Code:
    /*
     *  This program is designed to automate the normalisation process.
     */
    package pkgAutoNormalise;
    
    import java.io.*;
    import java.util.Scanner;
    
    class AutoNormalise {  
        
      public static void main(String args[]){
      FileOutputStream OutStream;
      PrintStream InStream; // declare a print stream object
     
      Scanner input = new Scanner(System.in); // create input scanner
      int intFields, intRows; // declare variables
    
     
      // - - - - - - - - - - - - - - - - - - - - -
      // C O N S T R U C T O R   G E N E R A T O R
      // - - - - - - - - - - - - - - - - - - - - -
     
      // create fields
      System.out.println("Enter number of fields:");
      intFields = input.nextInt();
      String arrayFieldName[] = new String[intFields+1];
      String arrayNewFieldName[] = new String[intFields+1];
      input.nextLine(); // simple error handling
      for(int x = 1; x <= intFields; x++) {
          System.out.println("\nEnter name of field " + x + ":");
          arrayFieldName[x] = input.nextLine();
          arrayNewFieldName[x] = "new" + arrayFieldName[x];
      } // end of for loop
     
      try {
          // create a new file output stream
          OutStream = new FileOutputStream("src//pkgAutoNormalise//Constructor.java");
          // connect print stream to the output stream
          InStream = new PrintStream(OutStream);
          // file streaming
          InStream.println ("package pkgAutoNormalise;");
          InStream.println ("public class Constructor {");
          // create variable declarations
          for(int x = 1; x <= intFields; x++) {
              InStream.println ("String " + arrayFieldName[x] + ";");
          } // end of for loop
          InStream.print ("    public Constructor(");
          // create constructor
          for(int x = 1; x <= intFields; x++) {
              if(x < intFields) {
                  InStream.print ("String " + arrayNewFieldName[x] + ", ");
              }
              else {
                  InStream.println ("String " + arrayNewFieldName[x] + ") {");
              }
          } // end of for loop
          for(int x = 1; x <= intFields; x++) {
              InStream.println ("        " + arrayFieldName[x] + " = " +
                      arrayNewFieldName[x] + ";");
          } // end of for loop
          InStream.println ("    }");
          // create getters
          for(int x = 1; x <= intFields; x++) {
              InStream.println ("public String get" + arrayFieldName[x] + "() {");
              InStream.println ("return " + arrayFieldName[x] + ";");
              InStream.println ("}");
          } // end of for loop
          InStream.println ("}");
          // message
          System.err.println ("\n[ Constructor generation successful ]");
          InStream.close();
      }
      catch (Exception e){
          System.err.println ("\n[ Constuctor generation failed ]");
      } // end of try catch
     
      // create objects
      try
      {
      File fileConstructor = new File("src//pkgAutoNormalise//Constructor.java");
      if(fileConstructor.exists()) {
          System.out.println("\nEnter number of record rows :");
          intRows = input.nextInt();
          Constructor[] arrayRecords = new Constructor[intRows+1];
          for(int x = 1; x <= intRows; x++) {
              for(int y = 1; y <= intFields; y++) {
                  System.out.println("Enter " + arrayFieldName[y] + " for record " + intRows + ":");
                  arrayNewFieldName[y] = input.nextLine();
              } // end of for loop
              if(intFields == 1) {
                  arrayRecords[x] = new Constructor(arrayNewFieldName[1]);
              }
              else if(intFields == 2) {
                  arrayRecords[x] = new Constructor(arrayNewFieldName[1],
                          arrayNewFieldName[2]);
              }
              else if(intFields == 3) {
                  arrayRecords[x] = new Constructor(arrayNewFieldName[1],
                          arrayNewFieldName[2], arrayNewFieldName[3]);
              }
              else if(intFields == 4) {
                  arrayRecords[x] = new Constructor(arrayNewFieldName[1],
                          arrayNewFieldName[2], arrayNewFieldName[3],
                          arrayNewFieldName[4]);
              }
              else if(intFields == 5) {
                  arrayRecords[x] = new Constructor(arrayNewFieldName[1],
                          arrayNewFieldName[2], arrayNewFieldName[3],
                          arrayNewFieldName[4], arrayNewFieldName[5]);
              }
              else if(intFields == 6) {
                  arrayRecords[x] = new Constructor(arrayNewFieldName[1],
                          arrayNewFieldName[2], arrayNewFieldName[3],
                          arrayNewFieldName[4], arrayNewFieldName[5],
                          arrayNewFieldName[6]);
              }
              else if(intFields == 7) {
                  arrayRecords[x] = new Constructor(arrayNewFieldName[1],
                          arrayNewFieldName[2], arrayNewFieldName[3],
                          arrayNewFieldName[4], arrayNewFieldName[5],
                          arrayNewFieldName[6], arrayNewFieldName[7]);
              }
              else if(intFields == 8) {
                  arrayRecords[x] = new Constructor(arrayNewFieldName[1],
                          arrayNewFieldName[2], arrayNewFieldName[3],
                          arrayNewFieldName[4], arrayNewFieldName[5],
                          arrayNewFieldName[6], arrayNewFieldName[7],
                          arrayNewFieldName[8]);
              }
              else if(intFields == 9) {
                  arrayRecords[x] = new Constructor(arrayNewFieldName[1],
                          arrayNewFieldName[2], arrayNewFieldName[3],
                          arrayNewFieldName[4], arrayNewFieldName[5],
                          arrayNewFieldName[6], arrayNewFieldName[7],
                          arrayNewFieldName[8], arrayNewFieldName[9]);
              }
              else if(intFields == 10) {
                  arrayRecords[x] = new Constructor(arrayNewFieldName[1],
                          arrayNewFieldName[2], arrayNewFieldName[3],
                          arrayNewFieldName[4], arrayNewFieldName[5],
                          arrayNewFieldName[6], arrayNewFieldName[7],
                          arrayNewFieldName[8], arrayNewFieldName[9],
                          arrayNewFieldName[10]);
              }
              else {
                  System.out.println("[ Program can't handle more than 10 fields ]");
              } // end of else if
          } // end of for loop
          for(int x = 1; x <= intFields; x++) {
              //
          } // end of for loop
      } // end of if statment
      }
      catch(Exception e) {
          // error handling
      }
     
      } // end of main method
     
    } // end of AutoNormalise class
    ERROR:
    init:
    deps-clean:
    Updating property file: C:\Users\Admin\Desktop\projAutoNormalise\build\built-clean.properties
    Deleting directory C:\Users\Admin\Desktop\projAutoNormalise\build
    clean:
    init:
    deps-jar:
    Created dir: C:\Users\Admin\Desktop\projAutoNormalise\build
    Updating property file: C:\Users\Admin\Desktop\projAutoNormalise\build\built-jar.properties
    Created dir: C:\Users\Admin\Desktop\projAutoNormalise\build\classes
    Created dir: C:\Users\Admin\Desktop\projAutoNormalise\build\empty
    Created dir: C:\Users\Admin\Desktop\projAutoNormalise\build\generated-sources\ap-source-output
    Compiling 1 source file to C:\Users\Admin\Desktop\projAutoNormalise\build\classes
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\AutoNormalise.java:84: error: cannot find symbol
    Constructor[] arrayRecords = new Constructor[intRows+1];
    symbol: class Constructor
    location: class AutoNormalise
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\AutoNormalise.java:84: error: cannot find symbol
    Constructor[] arrayRecords = new Constructor[intRows+1];
    symbol: class Constructor
    location: class AutoNormalise
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\AutoNormalise.java:91: error: cannot find symbol
    arrayRecords[x] = new Constructor(arrayNewFieldName[1]);
    symbol: class Constructor
    location: class AutoNormalise
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\AutoNormalise.java:94: error: cannot find symbol
    arrayRecords[x] = new Constructor(arrayNewFieldName[1],
    symbol: class Constructor
    location: class AutoNormalise
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\AutoNormalise.java:98: error: cannot find symbol
    arrayRecords[x] = new Constructor(arrayNewFieldName[1],
    symbol: class Constructor
    location: class AutoNormalise
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\AutoNormalise.java:102: error: cannot find symbol
    arrayRecords[x] = new Constructor(arrayNewFieldName[1],
    symbol: class Constructor
    location: class AutoNormalise
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\AutoNormalise.java:107: error: cannot find symbol
    arrayRecords[x] = new Constructor(arrayNewFieldName[1],
    symbol: class Constructor
    location: class AutoNormalise
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\AutoNormalise.java:112: error: cannot find symbol
    arrayRecords[x] = new Constructor(arrayNewFieldName[1],
    symbol: class Constructor
    location: class AutoNormalise
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\AutoNormalise.java:118: error: cannot find symbol
    arrayRecords[x] = new Constructor(arrayNewFieldName[1],
    symbol: class Constructor
    location: class AutoNormalise
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\AutoNormalise.java:124: error: cannot find symbol
    arrayRecords[x] = new Constructor(arrayNewFieldName[1],
    symbol: class Constructor
    location: class AutoNormalise
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\AutoNormalise.java:131: error: cannot find symbol
    arrayRecords[x] = new Constructor(arrayNewFieldName[1],
    symbol: class Constructor
    location: class AutoNormalise
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\AutoNormalise.java:138: error: cannot find symbol
    arrayRecords[x] = new Constructor(arrayNewFieldName[1],
    symbol: class Constructor
    location: class AutoNormalise
    12 errors
    C:\Users\Admin\Desktop\projAutoNormalise\nbproject\build-impl.xml:603: The following error occurred while executing this line:
    C:\Users\Admin\Desktop\projAutoNormalise\nbproject\build-impl.xml:244: Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 0 seconds)
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,699
    Rep Power
    347
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\AutoNormalise.java:84: error: cannot find symbol Constructor[] arrayRecords = new Constructor[intRows+1];
    symbol: class Constructor
    Where is the definition for the Constructor class?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    1
    The program creates it.
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,699
    Rep Power
    347
    The program needs for the class to exist when the program is being compiled so the compiler can use it.

    BTW Constructor is the name of a Java SE class.
    Last edited by NormR; July 28th, 2013 at 12:00 PM.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    1
    I do get less errors when I create the ANConstructor class but I still get red underlines for these lines:
    arrayRecords[x] = new ANConstructor(arrayNewFieldName[1]);
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    1
    If I create the ANConstructor class with the following code it removes all the red underlines from the code in the first post but then I get a red underline for the ANConstructor class.

    Code:
    package pkgAutoNormalise;
    
    public class ANConstructor {
    
        ANConstructor(...) {
            throw new UnsupportedOperationException("Not yet implemented");
        }
        
    }
    ERROR:
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\ANConstructor.java:5: error: illegal start of type
    ANConstructor(...) {
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\ANConstructor.java:5: error: <identifier> expected
    ANConstructor(...) {
    2 errors
  12. #7
  13. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,699
    Rep Power
    347
    I still get red underlines
    Can you copy the full text of the error message that describes the problem and paste it here?

    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\ANConstructor.java:5: error: illegal start of type ANConstructor(...) {
    The code needs a type and an identifier.
    Last edited by NormR; July 28th, 2013 at 12:12 PM.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    1
    There'll be a variable amount of parameters with different names each time.

    ANConstructor ERROR:
    init:
    deps-clean:
    Updating property file: C:\Users\Admin\Desktop\projAutoNormalise\build\built-clean.properties
    Deleting directory C:\Users\Admin\Desktop\projAutoNormalise\build
    clean:
    init:
    deps-jar:
    Created dir: C:\Users\Admin\Desktop\projAutoNormalise\build
    Updating property file: C:\Users\Admin\Desktop\projAutoNormalise\build\built-jar.properties
    Created dir: C:\Users\Admin\Desktop\projAutoNormalise\build\classes
    Created dir: C:\Users\Admin\Desktop\projAutoNormalise\build\empty
    Created dir: C:\Users\Admin\Desktop\projAutoNormalise\build\generated-sources\ap-source-output
    Compiling 2 source files to C:\Users\Admin\Desktop\projAutoNormalise\build\classes
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\ANConstructor.java:5: error: illegal start of type
    ANConstructor(...) {
    C:\Users\Admin\Desktop\projAutoNormalise\src\pkgAutoNormalise\ANConstructor.java:5: error: <identifier> expected
    ANConstructor(...) {
    2 errors
    C:\Users\Admin\Desktop\projAutoNormalise\nbproject\build-impl.xml:603: The following error occurred while executing this line:
    C:\Users\Admin\Desktop\projAutoNormalise\nbproject\build-impl.xml:244: Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 0 seconds)
  16. #9
  17. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,699
    Rep Power
    347
    There'll be a variable amount of parameters with different names each time.
    I don't know how to do that, or if it can be done. The ... notation creates an array. The array has one name and one type. It's size is created as needed.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    1
    Damn Oracle holding my ideas/creations back lol
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    1
    I don't understand why it isn't compiling though if you look at the original code. The section of code with red underlines is within a try catch and it still persists.
  22. #12
  23. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,699
    Rep Power
    347
    I don't understand why it isn't compiling
    What code is not compiling? What are the error messages from the compiler?
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    1
    They're in the first post (I'm using NetBeans btw).
  26. #14
  27. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,699
    Rep Power
    347
    The problems in post#1 was answered in post#2.
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    37
    Rep Power
    1
    I'll just run it with the errors because it'll work anyway but thanks for the quick responses NormR.

IMN logo majestic logo threadwatch logo seochat tools logo