/*
* 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