diff --git a/src/Main.java b/src/Main.java index 9aafd5a..3618224 100644 --- a/src/Main.java +++ b/src/Main.java @@ -14,167 +14,100 @@ public class Main { public static void main(String[] args) { -// Scanner sc = new Scanner(System.in); -// -// Screen screen = new Screen(20, 40, true);//20 rows, 40column, hasBorder -// screen.useBoxSet();//use box-window char -// screen.setTitle("Student Info"); - -// -// Label label1 = new Label(4,3); -// label1.setText("FirstName:"); -// label1.place(screen); -// -// TextBox txtFirstName = new TextBox(3,13); -// txtFirstName.setWidth(23); -// txtFirstName.place(screen); -// -// Label label2 = new Label(7,3); -// label2.setText("LastName:"); -// label2.place(screen); -// -// TextBox txtLastName = new TextBox(6,13); -// txtLastName.setWidth(23); -// txtLastName.place(screen); -// -// Label label3 = new Label(10,3); -// label3.setText("DOB:"); -// label3.place(screen); -// -// TextBox txtDOB = new TextBox(9,13); -// txtDOB.setWidth(23); -// txtDOB.place(screen); -// -// Label label4 = new Label(13,3); -// label4.setText("Age:"); -// label4.place(screen); -// -// TextBox txtAge = new TextBox(12,13); -// txtAge.setWidth(23); -// txtAge.place(screen); -// -// Label label5 = new Label(16,3); -// label5.setText("Course:"); -// label5.place(screen); -// -// TextBox txtCourse = new TextBox(15,13); -// txtCourse.setWidth(23); -// txtCourse.place(screen); -// -// screen.display(); -// -// CTable table = new CTable(new String[]{"Full Name","DOB","Age","Course"}); -// table.useBoxSet(); -// -// -// while (true){ -// //clear textbox -// txtFirstName.clear(); -// txtLastName.clear(); -// txtAge.clear(); -// txtDOB.clear(); -// txtCourse.clear(); -// -// -// System.out.println("FirstName:"); -// String firstname = sc.nextLine(); -// txtFirstName.setText(firstname); -// screen.display(); -// -// System.out.println("LastName:"); -// String lastname = sc.nextLine(); -// txtLastName.setText(lastname); -// screen.display(); -// -// System.out.println("DOB:"); -// String dob = sc.nextLine(); -// txtDOB.setText(dob); -// screen.display(); -// -// System.out.println("LastName:"); -// String age = sc.nextLine(); -// txtAge.setText(age); -// screen.display(); -// -// System.out.println("LastName:"); -// String course = sc.nextLine(); -// txtCourse.setText(course); -// screen.display(); -// -// table.addRow(new String[]{firstname+" "+lastname,dob,age,course}); -// table.display(); -// -// -// -// } - - - System.out.println("View Menu:"); - - String[] header = {"Id", "Product Name", "Quantity", "Price"}; - - CTable table = new CTable(header); - // table.useBoxSet(); - table.hasSeparator(true); - table.addRow("f011", "Fries", "10", "70.00"); - table.addRow("b212", "Burger", "10", "30.00"); - table.addRow("fc11", "Fried Chicken", "10", "110.50"); - table.addRow("f011", "Fries", "10", "70.00"); - table.addRow("s930", "Sundae", "10", "30.00"); - - table.setColumnAlignment(2,Position.CENTER); - table.setColumnAlignment(3,Position.END); - - //print table - // table.display(); - - int qtyTotal = table.getIntTotal(2); - float priceTotal = table.getFloatTotal(3); - - List> findItem = table.findRows(0,"f011"); - - CTable foundItems = new CTable(header); - // foundItems.useBoxSet(); - foundItems.addList(findItem); - // foundItems.display(); - - System.out.println("Total Qty:"+qtyTotal); - System.out.println("Total Price:"+priceTotal); - - - - String[][] arr = { - {"One", "Two","Three"}, - {"One", "Two","Three"}, - {"One", "Two","Three"}, - {"One", "Two","Three"}, - }; - String[] h = {"1","2","3"}; - - CTable table3 = new CTable(arr,h); - - table3.display(); - -// -// -// List productName =table.getColumn(1); -// System.out.println(productName); -// List friedChicken =table.getRow(2); -// System.out.println(friedChicken); -// -// //uupdate or pass a new 2d array - - CList list = new CList(); - list.useBoxSet(); - // list.setWidth(20); - list.setTitle("Fruits",Position.CENTER); - - list.addItem("Apple"); - list.addItem("Banana"); - list.addItem("Mango"); - list.addItem("Banana"); - - // list.display(); + Scanner sc = new Scanner(System.in); + + Screen screen = new Screen(20, 40, true);//20 rows, 40column, hasBorder + //screen.useBoxSet();//use box-window char + screen.setTitle("Student Info"); + + + Label label1 = new Label(4, 3); + label1.setText("FirstName:"); + label1.place(screen); + + TextBox txtFirstName = new TextBox(3, 13); + txtFirstName.setWidth(23); + txtFirstName.place(screen); + + Label label2 = new Label(7, 3); + label2.setText("LastName:"); + label2.place(screen); + + TextBox txtLastName = new TextBox(6, 13); + txtLastName.setWidth(23); + txtLastName.place(screen); + + Label label3 = new Label(10, 3); + label3.setText("DOB:"); + label3.place(screen); + + TextBox txtDOB = new TextBox(9, 13); + txtDOB.setWidth(23); + txtDOB.place(screen); + + Label label4 = new Label(13, 3); + label4.setText("Age:"); + label4.place(screen); + + TextBox txtAge = new TextBox(12, 13); + txtAge.setWidth(23); + txtAge.place(screen); + + Label label5 = new Label(16, 3); + label5.setText("Course:"); + label5.place(screen); + + TextBox txtCourse = new TextBox(15, 13); + txtCourse.setWidth(23); + txtCourse.place(screen); + + screen.display(); + + CTable table = new CTable("Full Name", "DOB", "Age", "Course"); + + + + + while (true){ + //clear textbox + txtFirstName.clear(); + txtLastName.clear(); + txtAge.clear(); + txtDOB.clear(); + txtCourse.clear(); + + + System.out.println("FirstName:"); + String firstname = sc.nextLine(); + txtFirstName.setText(firstname); + screen.display(); + + System.out.println("LastName:"); + String lastname = sc.nextLine(); + txtLastName.setText(lastname); + screen.display(); + + System.out.println("DOB:"); + String dob = sc.nextLine(); + txtDOB.setText(dob); + screen.display(); + + System.out.println("LastName:"); + String age = sc.nextLine(); + txtAge.setText(age); + screen.display(); + + System.out.println("LastName:"); + String course = sc.nextLine(); + txtCourse.setText(course); + screen.display(); + + table.addRow(firstname+" "+lastname,dob,age,course); + table.display(); + + + + } diff --git a/src/cscreen/classes/CharSets.java b/src/cscreen/classes/CharSets.java index ead4a70..0309569 100644 --- a/src/cscreen/classes/CharSets.java +++ b/src/cscreen/classes/CharSets.java @@ -66,7 +66,7 @@ private static CharSets normalSetInstance(){ } - if(!boxSetInstance().isCalled){ + if(!charSetsInstance.isCalled){ charSetsInstance.isBox =false; charSetsInstance.normalSets(); diff --git a/src/cscreen/classes/Utilities.java b/src/cscreen/classes/Utilities.java index 1f62b42..9890b0a 100644 --- a/src/cscreen/classes/Utilities.java +++ b/src/cscreen/classes/Utilities.java @@ -18,9 +18,11 @@ public static int getMax(String[] arr){ } - public static int[] getMaxByColumn(List> arr) { + public static int[] getMaxByColumn(List> arr){ int[] arrMax = new int[arr.get(0).size()]; + + for (int j = 0; j < arr.get(0).size(); j++) { String[] temp = new String[arr.size()]; @@ -28,6 +30,7 @@ public static int[] getMaxByColumn(List> arr) { for (int i = 0; i < arr.size(); i++) { temp[i] = arr.get(i).get(j); } + arrMax[j] = getMax(temp); } return arrMax; diff --git a/src/cscreen/components/CTable.java b/src/cscreen/components/CTable.java index 7fb11b2..229b6eb 100644 --- a/src/cscreen/components/CTable.java +++ b/src/cscreen/components/CTable.java @@ -172,7 +172,8 @@ private int combineRow(List> arr) { //System.out.println(alignments); - String fline = Utilities.alignedString(arr.get(i).get(j), space, alignments.getOrDefault(j, null)); + + String fline= Utilities.alignedString(arr.get(i).get(j), space, alignments.getOrDefault(j, null)); line = line + fline +separator;