J o e
JoE's StOrY
J o e
  • 분류 전체보기 (206)
    • workSpace (184)
      • 도메인 지식 (2)
      • ALGORITHM (39)
      • ANDROID (3)
      • JS (0)
      • JAVA (21)
      • MYSQL (6)
      • NETWORK (3)
      • PYTHON (91)
      • LINUX (9)
      • PROJECT (4)
    • Others (20)
      • Opic (1)
      • myLife (17)
      • popSong (1)
      • 정보처리기사 (1)
    • 훈빠의 특강 (0)
      • opencv (0)
      • python (0)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

  • The code with long statements is⋯
  • 매일 매일이 행복하고 밝은 날이 될거에요

인기 글

태그

  • 이미지 연산
  • Fully Connected Network
  • read_html
  • Python
  • java
  • numpy
  • linearclassification
  • 단어의 개수
  • How to create a GUI in Java with JFrame?
  • MySQL
  • sort_value
  • full loss
  • 태블릿 연동
  • 넘파이 문제
  • 넘파이함수
  • sort_index
  • DTO
  • ㅖ43
  • 파이썬
  • dao

최근 댓글

최근 글

티스토리

J o e

WHY?

[Python] 성적입출력 프로그램 (MVC pattern)
workSpace/PYTHON

[Python] 성적입출력 프로그램 (MVC pattern)

2020. 12. 26. 20:20
# 1명의 학생을 정의하는 클래스
class Student:  # 한 학생의 정보 및 성적처리 . 캡슐화 (주의할 점~! C언어나, 자바처럼 구현x, 하나라고 생각해야한다.)
    def __init__(self, name, number, kor, eng, math):  # 생성자로 각 멤버변수 생성.
        self.name = name  # 파라메터로 받아서 멤버변수에 저장한다.
        self.number = number
        self.kor = kor
        self.eng = eng
        self.math = math

    def calculrator(self):  # 점수를 계산하는 메서드
        self.total = self.kor + self.eng + self.math
        self.avg = self.total / 3

    def printInfo(self):  # 입력한 정보를 보여주는 메서드
        print("name :", self.name)
        print("number :", self.number)
        print("kor :", self.kor)
        print("eng :", self.eng)
        print("math :", self.math)
        print("total :", self.total)
        print("avg :", self.avg)
        print("---------------------")


# Dao = database access object - 작업 전담 클래스
class Dao:  # 정보를 저장해주는 클래스
    def __init__(self):  # 생성자
        self.datas = []  # 맴버변수를 리스트로 선언해준다.

    def insert(self, sum):  # 파라메터로 sum 을 받아와서 클래서에서 사용할 수 있게 해준다.
        self.datas.append(sum)  # 멤버변수인 리스트에 데이터를 추가, 저장해준다.

    def selectAll(self):  # 맴버변수를 보여줄 메서드 선어
        return self.datas  # 멤버변수에 저장된 리스트를 반환해 준다.


class Service:  # 사용자에게 UI를 보여주는 클래스
    def __init__(self):  # 생성자 선언
        self.dao = Dao()  # 정보를 저장해주는 클래스를 받아와서 맴버변수로 선언해준다.

    def addStudent(self):  # 학생의 정보를 사용자에게 받아와서 Dao 클래스로 넘겨주는 메서드
        name = input("이름 :")
        number = int(input("번호 :"))
        kor = int(input("국어 :"))
        eng = int(input("영어 :"))
        math = int(input("수학 :"))
        s = Student(name, number, kor, eng, math)  # 위의 Student 클래스를 불러와서 지역변수 선언을 해주고 ,
        # 사용자에게 입력받은 값을 저장 시킨다.
        s.calculrator()  # Student 클래스의 계산 메서드를 불러와서 실행시킨다.
        self.dao.insert(s)  # 계산 까지된 값들을 저장 클래스에 넘겨서 저장클래스 insert 메서드를 사용해 리스트에 넣어준다.

    def printAll(self):
        all = self.dao.selectAll()
        for i in all:
            i.printInfo()


def main():
    service = Service()
    service.addStudent()
    service.addStudent()
    for i in range(3):
        service.addStudent()
    service.printAll()

main()

'workSpace > PYTHON' 카테고리의 다른 글

[Python] 주소록 프로그램  (0) 2020.12.26
[Python] 제품입출력 프로그램 (MVC pattern)  (0) 2020.12.26
[Python] bubble, insert, select sorting + 이진탐색  (0) 2020.12.26
[Python] 리스트 요소의 합과 평균, 최대값, 최소값 출력하기.  (0) 2020.12.26
[Python] 기본 문법. (복붙해서 사용하기)  (0) 2020.12.26
    'workSpace/PYTHON' 카테고리의 다른 글
    • [Python] 주소록 프로그램
    • [Python] 제품입출력 프로그램 (MVC pattern)
    • [Python] bubble, insert, select sorting + 이진탐색
    • [Python] 리스트 요소의 합과 평균, 최대값, 최소값 출력하기.
    J o e
    J o e
    나의 과거를 기록합니다.

    티스토리툴바