Skip to content

Commit

Permalink
added Column Alignment
Browse files Browse the repository at this point in the history
-fixed minor bugs
  • Loading branch information
soybean15 committed Aug 20, 2022
1 parent 87526c2 commit 4dca426
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 164 deletions.
255 changes: 94 additions & 161 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<String >> 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<String> productName =table.getColumn(1);
// System.out.println(productName);
// List<String> 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();



}



Expand Down
2 changes: 1 addition & 1 deletion src/cscreen/classes/CharSets.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private static CharSets normalSetInstance(){


}
if(!boxSetInstance().isCalled){
if(!charSetsInstance.isCalled){
charSetsInstance.isBox =false;
charSetsInstance.normalSets();

Expand Down
5 changes: 4 additions & 1 deletion src/cscreen/classes/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ public static int getMax(String[] arr){
}


public static int[] getMaxByColumn(List<List<String>> arr) {
public static int[] getMaxByColumn(List<List<String>> 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()];

for (int i = 0; i < arr.size(); i++) {
temp[i] = arr.get(i).get(j);
}

arrMax[j] = getMax(temp);
}
return arrMax;
Expand Down
3 changes: 2 additions & 1 deletion src/cscreen/components/CTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ private int combineRow(List<List<String>> 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;

Expand Down

0 comments on commit 4dca426

Please sign in to comment.