티스토리 뷰
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | package oop; import java.util.Scanner; class Score{ private String name; private int kor, eng, math, sum; float avg; public void setName(String name) {this.name = name;} public String getName() {return this.name;} public void setKor(int kor) {this.kor = kor;} public int getKor() {return this.kor;} public void setEng(int eng) {this.eng = eng;} public int getEng() {return this.eng;} public void setMath(int math) {this.math = math;} public int getMath() {return this.math;} public void sum() {this.sum = this.kor + this.eng + this.math;} public void avg() {this.avg = this.sum / 3;} public float showAge() {return this.avg;} public String toString() { return "국어: "+kor+", 영어:"+eng+", 수학:"+math+", 합계:" +sum + "평균: " + avg; } } public class ScoreApp{ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Score[] arr = new Score[2]; for(int i=0; i<arr.length; i++) { Score student = new Score(); System.out.println("이름: "); student.setName(scanner.next()); System.out.println("국어점수: "); student.setKor(scanner.nextInt()); System.out.println("영어점수: "); student.setEng(scanner.nextInt()); System.out.println("수학점수: "); student.setMath(scanner.nextInt()); student.sum(); student.avg(); System.out.println("평균: "+student.showAge()); arr[i]=student; } for(int i=0; i<arr.length; i++) { arr[i].toString(); } } } | cs |
'1. 자바' 카테고리의 다른 글
File Handler Proxy.java with Generic (0) | 2020.08.26 |
---|---|
자바/JPA/2020-08-26/ application.propetires 한글깨짐 해결하기 (0) | 2020.08.26 |
Array - Player.java (0) | 2020.08.14 |
OOP - Phone.java (0) | 2020.08.14 |
CRUD - Person.java (0) | 2020.08.14 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- docker
- Git
- mariadb
- vscode
- nodejs
- COLAB
- Mongo
- FLASK
- Eclipse
- intellij
- terms
- KAFKA
- jQuery
- SpringBoot
- JUnit
- SQLAlchemy
- Mlearn
- ERD
- maven
- springMVC
- AWS
- Java
- React
- Algorithm
- database
- Django
- Python
- Oracle
- tensorflow
- JPA
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
글 보관함