[go: up one dir, main page]

0% found this document useful (0 votes)
458 views2 pages

Onmysourcecodegenerator

This document contains the source code for a class called OnMySourceCodeGENERATOR. The class contains a static method called OnMySourceCodeGENERATOR that takes a string parameter P. The method generates Java source code as strings that define character arrays for the input string and a method to add the character arrays to a string. It prints the generated source code.

Uploaded by

api-301800569
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
458 views2 pages

Onmysourcecodegenerator

This document contains the source code for a class called OnMySourceCodeGENERATOR. The class contains a static method called OnMySourceCodeGENERATOR that takes a string parameter P. The method generates Java source code as strings that define character arrays for the input string and a method to add the character arrays to a string. It prints the generated source code.

Uploaded by

api-301800569
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

/* CSE 311

*
* OnMySourceCodeGENERATOR
*
* Name: Elizabeth Moore
* UW NetID: emoore3
*
*/
public class OnMySourceCodeGENERATOR {
public static void OnMySourceCodeGENERATOR(String P) {
char tab = (char)9;
char quote = (char)34;
char newLine = (char)10;
char backSlash = (char)92;
String string1 = "public class POnMySourceCode{" + newLine
+ P + newLine;
System.out.print(string1);
printAsArray("s1", string1);
String string2 = "" + tab + "public static String
addArr(String str, String name, char[] s){" + newLine
+ tab + tab + "str += " + quote + " static char[] " +
quote + " + name + " + quote + " = {" + backSlash + "n" + quote +
";" + newLine
+ tab + tab + "for(int i = 0; i < s.length; i++){" +
newLine
+ tab + tab + tab + "str += " + " + (int)s[i] + " +
quote + ", " + quote + ";" + newLine
+ tab + tab + tab + "if(i % 21 == 20){" + newLine
+ tab + tab + tab + tab + "str += " + quote +
backSlash + "n " + backSlash + "t" + quote + ";" + newLine
+ tab + tab + tab + "}" + newLine
+ tab + tab + "}" + newLine
+ tab + tab + "str += " + quote + backSlash + "n\t};"
+ backSlash + "n" + quote + ";" + newLine
+ tab + tab + "return str;" + newLine
+ tab + "}" + newLine
+ newLine
+ tab + "public static void main(String[] args){" +
newLine
+ tab + tab + "String code = new String(s1);" +
newLine
+ tab + tab + "code = addArr(code, " + quote + "s1" +

quote + ", s1);" + newLine


+ tab + tab + "code = addArr(code, " + quote + "s2" +
quote + ", s2);" + newLine
+ tab + tab + "code += new String(s2);" + newLine
+ tab + tab + "P(code);" + newLine
+ tab + "}" + newLine
+ "}" + newLine;
printAsArray("s2", string2);
System.out.print(string2);
}
public static void printAsArray(String name, String str){
System.out.print(" static char[] " + name + " = {\n" );
for (int i = 0; i < str.length(); i++){
System.out.print( + (int)str.charAt(i) + ", ");
if(i % 21 == 20) {System.out.print("\n \t");};
}
System.out.print("\n\t};\n");
}
}

You might also like