T. 김동식
JAVA
1001학번 Lee 국어(100점), 수학(50점)
1002학번 Kim 국어(70점), 수학(85점), 영어(100점)
클래스 Student, Subject를 생성해 두 학생의 과목성적과 총점을 출력하라.
0. 설계
1. Subject1 설정
private String subName;
private int score;
public Subject1() {}
public void setSubName(String subName) {
this.subName = subName;
}
public String getSubName() {
return subName;
}
public void setScore(int score) {
this.score = score;
}
public int getScore() {
return score;
}
2. Student1 설정
int studentID;
String studentName;
ArrayList<Subject1> subjectList;
public Student1() {}
public Student1(int studentID, String studentName) {
this.studentID = studentID;
this.studentName = studentName;
subjectList = new ArrayList<Subject1>();
}
void student_subjectInfo(String subName, int score){
Subject1 subject1 = new Subject1();
subject1.setSubName(subName);
subject1.setScore(score);
subjectList.add(subject1);
}
void showinfo() {
int total = 0;
System.out.println(studentID+"학번의 "+studentName+"학생");
for(Subject1 s:subjectList) {
total = total+s.getScore();
System.out.println(s.getSubName()+"과목의 점수는 "+s.getScore());
}
System.out.println(total+"이 총합");
}
3. StudentTest1 설정
Student1 lee = new Student1(100, "a");
lee.student_subjectInfo("과목1", 1);
lee.student_subjectInfo("과목2", 2);
lee.student_subjectInfo("과목3", 3);
lee.showinfo();
System.out.println("---------");
Student1 kim = new Student1(100, "a");
kim.student_subjectInfo("과목1", 1);
kim.student_subjectInfo("과목2", 3);
kim.student_subjectInfo("과목3", 3);
kim.showinfo();
java.util.Scanner
int input = 0; // 사용자입력을 저장할 공간
java.util.Scanner s = new java.util.Scanner(System.in);
input = s.nextInt(); // input . 입력받은 값을 변수 에 저장한다
Python
복습
https://sanghee.tistory.com/59/#python_sanghee
print(type((10)))
print(type((10, 20)))
------------------------------
<class 'int'>
<class 'tuple'>
# and or
print(4<5 and 4<5)
print(4>5 or 4>5)
------------------------------
True
False
# 비트연산자
print(1&3) #and
print(1|3) #or
print(1^3) #xor
print(~3) #tilder
------------------------------
1
3
2
-4
자료구조 list[], tuple(), 문자열"", dictionary{}
공통점
- 인덱싱(slicing, 조각조각잘라내다)이 있다.
- for문과 함께 사용한다.
차이점
- list는 요소의 값을 변경할 수 있다. mutable
- tuple, 문자열은 요소의 값을 변경할 수 있다. immutable
# 인덱싱(slicing, 조각조각잘라내다)이 있다.
list2= [1, 2, 3]
tuple1= (1, 2, 3)
str1= "문자열이다"
dictionary1= {1:11, 2:22, 3:33}
print(list2[1])
print(tuple1[1])
print(str1[1])
print(dictionary1[1])
------------------------------
2
2
자
11
# list, 요소의 값을 변경할 수 있다. mutable
type(list2)
list2[1] = '산'
print(list2)
------------------------------
[1, '산', 3]
# tuple(),문자열, 딕셔너리 immutable 가변의, 요소의 값 변경 불가능
type(tuple1)
tuple1[1] = '산'
print(tuple1)
------------------------------
TypeError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_11920\4213741889.py in <module>
1 # immutable 가변의, 요소의 값 변경 불가능
2 type(tuple1)
----> 3 tuple1[1] = '산'
4 print(tuple1)
TypeError: 'tuple' object does not support item assignment
# 리스트[:]의 사용법
li1 = [1, '산', True]
print(li1[0])
print(li1[0:2]) # a:b a부터b까지
print(li1[:2]) # :b b까지
print(li1[:]) #처음부터 끝까지
print(li1[-1]) #마지막부터 카운드
print(li1[-2]) #마지막부터 카운드
------------------------------
1
[1, '산']
[1, '산']
[1, '산', True]
True
산
# 튜플[:]의 사용법
print(tu1[0])
print(tu1[0:2]) # a:b a부터b까지
print(tu1[:2]) # :b b까지
print(tu1[:]) #처음부터 끝까지
print(tu1[-1]) #마지막부터 카운드
print(tu1[-2]) #마지막부터 카운드
------------------------------
1
(1, '강')
(1, '강')
(1, '강', True)
True
강
# for i in 리스트, 줄바꿈하지 않는 출력
for i in li1:
print(i, end="")
print()
# for i in 튜플
for i in tu1:
print(i, end="")
print()
# for i in 문자열
for i in str1:
print(i, end="")
------------------------------
1산True
1강True
문자열이다
# seperator 사이구분자
print("월", "화", "수")
print("월", "화", "수", sep=',')
for i in str1:
print(i, end='')
------------------------------
월 화 수
월,화,수
문자열이다