Data flow map on MVC pattern

                            Loader Flow 

                                (Stack)                     Front-end


-------------------------------------------------------------------------------------1 Front /Public Class (1+2)

package front;

import java.util.Scanner;

public class FrontEnd {

public FrontEnd(int recordIdx) {

this.controller(recordIdx); }



-------------------------------------------------------------------------------------2 Controller (2D Array) /Void

public void controller(int recordIndex) {

Scanner scanner = new Scanner(System.in);

String title = this.makeTitle();

String[][] menu = {

{"EXIT", "프로그램을 종료합니다.~"}, 

{"메인", "연산하기", "끝내기"}, 

{"연산", "새로운 연산", "이어서 연산", "이전화면"}};


-------------------------------------------------------------------------------------3 display (show the controller on the display)

/* 출력 전용 메서드1 */

public void display(String text) {

System.out.print(text);

}

-------------------------------------------------------------------------------------4–1 controller (4-1+ 4-2)


public void controller(int recordIndex) {

Scanner scanner = new Scanner(System.in);

String title = this.makeTitle();

String[][] menu = {

{"EXIT", "프로그램을 종료합니다.~"}, 

{"메인", "연산하기", "끝내기"}, 

{"연산", "새로운 연산", "이어서 연산", "이전화면"}};

-------------------------------------------------------------------------------------4 MakeSubMenu

public String makeSubMenu(String[] menu) {

StringBuffer subMenu = new StringBuffer();

subMenu.append("  [ " + menu[0] + " ]");

subMenu.append(" _____________________________________");

for(int underBar=0; underBar <= 4-menu[0].length(); underBar++) {

subMenu.append("_");}

subMenu.append("\n\n");

if(menu.length <= 2) {subMenu.append("    " + menu[menu.length-1] + "  \n");

subMenu.append("  ________________________________________________\n");

}else {

for(int colIdx=1; colIdx<menu.length; colIdx++) {

if(colIdx == menu.length-1) { 

subMenu.append("0. " + menu[colIdx] + "  \n");

}else { subMenu.append("    "+ colIdx + ". " + menu[colIdx] + "     ");}

}

subMenu.append("  __________________________________ select : ");

}

return subMenu.toString();

}

-------------------------------------------------------------------------------------5 Controller 


public void controller(int recordIndex) {

Scanner scanner = new Scanner(System.in);

String title = this.makeTitle();

String[][] menu = {

{"EXIT", "프로그램을 종료합니다.~"}, 

{"메인", "연산하기", "끝내기"}, 

{"연산", "새로운 연산", "이어서 연산", "이전화면"}};

-------------------------------------------------------------------------------------6 Display


/* 출력 전용 메서드1 */

public void display(String text) {

System.out.print(text);

}


-------------------------------------------------------------------------------------7- Controller 


public void controller(int recordIndex) {

Scanner scanner = new Scanner(System.in);

String title = this.makeTitle();

String[][] menu = {

{"EXIT", "프로그램을 종료합니다.~"}, 

{"메인", "연산하기", "끝내기"}, 

{"연산", "새로운 연산", "이어서 연산", "이전화면"}}


-------------------------------------------------------------------------------------7 User input

public int userInput(Scanner scanner) {

return scanner.nextInt();

}


-------------------------------------------------------------------------------------8 Controller


public void controller(int recordIndex) {

Scanner scanner = new Scanner(System.in);

String title = this.makeTitle();

String[][] menu = {

{"EXIT", "프로그램을 종료합니다.~"}, 

{"메인", "연산하기", "끝내기"}, 

{"연산", "새로운 연산", "이어서 연산", "이전화면"}};


-------------------------------------------------------------------------------------9 IsintegerRange


int selectMenu;

boolean loopCheck = true;

while(loopCheck) {

/* 로딩 후 첫 화면 출력 */

this.display(title);

this.display(this.makeSubMenu(menu[recordIndex]));

/* 사용자 입력 --> 화면 이동 */

selectMenu = this.userInput(scanner);

if(this.isIntegerRange(selectMenu, 0, menu[recordIndex].length - 2)) {

recordIndex += (selectMenu == 0)? -1: 1;


if(recordIndex == 0) {

this.display(title);

this.display(this.makeSubMenu(menu[recordIndex]));

loopCheck = false; // 프로그램 종료

}else {

}


}else {

// 유효값이 아닌 경우 재입력 요청 >> 사용자 입력 반복

}

}

scanner.close();

}



------------------------------------------------------------------------------------10 Controller

public void controller(int recordIndex) {

Scanner scanner = new Scanner(System.in);

String title = this.makeTitle();

String[][] menu = {

{"EXIT", "프로그램을 종료합니다.~"}, 

{"메인", "연산하기", "끝내기"}, 

{"연산", "새로운 연산", "이어서 연산", "이전화면"}};

-------------------------------------------------------------------------------------11 Display


/* 출력 전용 메서드1 */

public void display(String text) {

System.out.print(text);

}

—----------------------------------------------------------------------------------appendix:Maketititle

public String makeTitle() {

StringBuffer title = new StringBuffer();

title.append("****************************************************\n\n");

title.append("     JS Framework Calculator  v1.0\n");

title.append("           Designed By HoonZzang\n\n");

title.append("****************************************************\n\n");

return title.toString();

}


Comments

Popular Posts