Login Register






Java subset language. filter_list
Author
Message
Java subset language. #1
So i just wanted to provide a comparison of 2 languages. the first is a custom "subset" of java designed for teach students programming.

It takes the code, and throws it through a sort of precompiler, which takes the statements and turns them into proper java. for the most part the statements are the same except for the removal of superfluous information.

I have provided the subset code, as well as the constructed java file the precompiler creates.

What would you rather learn? any opinions on the matter?

Code:
import files; String[] item = new String[10]; int[] qty = new int[10]; String[] parts = new String[10]; int[] partQty = new int[10]; int arrLength = 0; int arrLength2 = 0; void main() { countItems(); countParts(); showArray(); } void countItems() { int i = 0; while(isNextWord()) { String theWord = readWord(); int theInt = readInt(); i = linearSearch(theWord, item, arrLength); if (i < arrLength) { item[i] = theWord; qty[i] = qty[i] + theInt; } else { item[i]= theWord; qty[i] = theInt; arrLength = arrLength + 1; } } } void countParts() { for(int j = 0; j < arrLength; j = j + 1) { int f = openRead(item[j] + ".txt"); int i = 0; while(isNextWord(f)) { int theInt = readInt(f); String theWord = readWord(f); i = linearSearch(theWord, parts, arrLength2); if (i < arrLength2) { parts[i] = theWord; partQty[i] = partQty[i] + (theInt * qty[j]); } else { parts[i]= theWord; partQty[i] = theInt * qty[j]; arrLength2 = arrLength2 + 1; } } close(f); } } void showArray() { for(int j = 0; j < arrLength2; j = j + 1) { println(parts[j] + " " + partQty[j]); } } int linearSearch(String s, String[] a, int n) { int i = 0; int j = n; while (i < j) { if (equals(a[i], s)) { j = i; } else { i = i + 1; } } return i; }

Code:
public class TotalProducts { protected static final int MAX_INT = java.lang.Integer.MAX_VALUE; protected static final int MIN_INT = java.lang.Integer.MIN_VALUE; protected static final long MAX_LONG = java.lang.Long.MAX_VALUE; protected static final long MIN_LONG = java.lang.Long.MIN_VALUE; protected static final double PI = java.lang.Math.PI; private static java.util.Scanner mash_console_scanner = new java.util.Scanner(System.in); protected static java.lang.String[] item = new java.lang.String[10]; protected static int[] qty = new int[10]; protected static int arrLength = 0; public static void main(java.lang.String[] mash_args_param) throws java.lang.Exception { { TotalProducts.countItems(); TotalProducts.showArray(); } } protected static void countItems() { int i = 0; while (mash_console_scanner.hasNext()) { java.lang.String theWord = mash_console_scanner.next(); int theInt = mash_console_scanner.nextInt(); i = TotalProducts.linearSearch(theWord, TotalProducts.item, TotalProducts.arrLength); if (i < TotalProducts.arrLength) { item[i] = theWord; qty[i] = qty[i] + theInt; } else { item[i] = theWord; qty[i] = theInt; arrLength = TotalProducts.arrLength + 1; } } } protected static void showArray() { for (int j = 0; j < TotalProducts.arrLength; j = j + 1) { java.lang.System.out.println(item[j] + " " + qty[j]); } } protected static int linearSearch(java.lang.String s, java.lang.String[] a, int n) { int i = 0; int j = n; while (i < j) { if (a[i].equals(s)) { j = i; } else { i = i + 1; } } return i; } }

Reply