package day25;
import java.text.ChoiceFormat;
public class ArrayTest {
public static void main(String[] args) {
String [] name = {"한라산","백두산","금강산","설악산","내장산","명지산","광교산"};
int [] jum = {80,66,92,71,85,59,100};
String [] hak = {"F","D","C","B","A"};
double [] avg = {0,60,70,80,90}; // 반드시 오름차순 정열
// 학점구하기
ChoiceFormat cf = new ChoiceFormat(avg,hak);
// 출력하기
for(int i=0;i<jum.length;i++) {
System.out.println(name[i]+"\t"+jum[i]+"\t"+cf.format(jum[i]));
}
}
}
package day25;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.ChoiceFormat;
import java.text.DecimalFormat;
import java.util.ArrayList;
class SchoolDTO {
DecimalFormat df = new DecimalFormat("#,##0.0");
String name;
int kor,eng,mat;
int tot;
double avg;
String hak;
public SchoolDTO() {}
public SchoolDTO(String name, int kor, int eng, int mat) {
super();
this.name = name;
this.kor = kor;
this.eng = eng;
this.mat = mat;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getKor() {
return kor;
}
public void setKor(int kor) {
this.kor = kor;
}
public int getEng() {
return eng;
}
public void setEng(int eng) {
this.eng = eng;
}
public int getMat() {
return mat;
}
public void setMat(int mat) {
this.mat = mat;
}
public int getTot() {
return tot;
}
public void setTot(int tot) {
this.tot = tot;
}
public double getAvg() {
return avg;
}
public void setAvg(double avg) {
this.avg = avg;
}
public String getHak() {
return hak;
}
public void setHak(String hak) {
this.hak = hak;
}
@Override
public String toString() {
return "SchoolDTO [name=" + name + ", kor=" + kor + ", eng=" + eng + ", mat=" + mat + ", tot=" + tot + ", avg="
+ df.format(avg) + ", hak=" + hak + "]";
}
}
public class ArrayTest {
public static void main(String[] args) throws FileNotFoundException {
ArrayList<SchoolDTO> list = new ArrayList<SchoolDTO>();
FileReader fr = new FileReader("c:/data/01061.txt");
BufferedReader br = new BufferedReader(fr);
double [] avg1 = {0,60,70,80,90};
String [] hak1 = {"F","D","C","B","A"};
ChoiceFormat cf = new ChoiceFormat(avg1,hak1);
while(true) {
try {
String str = br.readLine();
if(str==null)break;
SchoolDTO dto = new SchoolDTO();
dto.setName(str.substring(0, 3));
dto.setKor(Integer.parseInt(str.substring(3, 6)));
dto.setEng(Integer.parseInt(str.substring(6, 9)));
dto.setMat(Integer.parseInt(str.substring(9, 12)));
dto.setTot(dto.getKor()+dto.getEng()+dto.getMat());
dto.setAvg((double)dto.getTot()/3);
dto.setHak(cf.format(dto.getAvg()));
list.add(dto);
} catch (IOException e) {
e.printStackTrace();
}
}
for(SchoolDTO a:list) {
System.out.println(a.toString());
}
}
}
package day25;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
class BuDTO {
String name;
String buseo;
public BuDTO() {}
public BuDTO(String name, String buseo) {
super();
this.name = name;
this.buseo = buseo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBuseo() {
return buseo;
}
public void setBuseo(String buseo) {
this.buseo = buseo;
}
@Override
public String toString() {
return "BuDTO [name=" + name + ", buseo=" + buseo + "]";
}
}
public class Test1 {
public static void main(String[] args) throws FileNotFoundException {
ArrayList<BuDTO> list = new ArrayList<BuDTO>();
FileReader fr = new FileReader("c:/data/01062.txt");
BufferedReader br = new BufferedReader(fr);
while(true) {
try {
String str = br.readLine();
if(str==null)break;
BuDTO dto = new BuDTO();
dto.setName(str.substring(0, 3));
dto.setBuseo(str.substring(3, 4));
if(dto.getBuseo().equals("i"))dto.setBuseo("인사과");
else if(dto.getBuseo().equals("j"))dto.setBuseo("재무과");
else if(dto.getBuseo().equals("c"))dto.setBuseo("총무과");
list.add(dto);
}
catch (IOException e) {
e.printStackTrace();
}
}
for(BuDTO a:list) {
System.out.println(a.toString());
}
}
}
package day25;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
class BuDTO {
String name;
String buseo;
public BuDTO() {}
public BuDTO(String name, String buseo) {
super();
this.name = name;
this.buseo = buseo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBuseo() {
return buseo;
}
public void setBuseo(String buseo) {
this.buseo = buseo;
}
@Override
public String toString() {
return "BuDTO [name=" + name + ", buseo=" + buseo + "]";
}
}
public class Test1 {
enum buseo {i("인사과"),j("자재과"),c("총무과") ;
private String value;
private buseo(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
public static void main(String[] args) throws FileNotFoundException {
ArrayList<BuDTO> list = new ArrayList<BuDTO>();
FileReader fr = new FileReader("c:/data/01062.txt");
BufferedReader br = new BufferedReader(fr);
while(true) {
try {
String str = br.readLine();
if(str==null)break;
BuDTO dto = new BuDTO();
String name =str.substring(0, 3);
String bu =str.substring(3, 4);
list.add(new BuDTO(name,buseo.valueOf(bu).getValue()));
}
catch (IOException e) {
e.printStackTrace();
}
}
for(BuDTO a:list) {
System.out.println(a.toString());
}
}
}
package day25;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
class BuDTO {
String name;
String buseo;
String gender;
public BuDTO() {}
public BuDTO(String name, String buseo, String gender) {
super();
this.name = name;
this.buseo = buseo;
this.gender = gender;
}
@Override
public String toString() {
return "BuDTO [name=" + name + ", buseo=" + buseo + ", gender=" + gender + "]";
}
}
public class Test1 {
enum buseo {i("인사과"),j("자재과"),c("총무과");
private String value;
private buseo(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
enum gen {f("여자"),m("남자");
private String value;
private gen(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
public static void main(String[] args) throws FileNotFoundException {
ArrayList<BuDTO> list = new ArrayList<BuDTO>();
FileReader fr = new FileReader("c:/data/01062.txt");
BufferedReader br = new BufferedReader(fr);
while(true) {
try {
String str = br.readLine();
if(str==null)break;
BuDTO dto = new BuDTO();
String name =str.substring(0, 3);
String bu =str.substring(3, 4);
String gender =str.substring(4, 5);
list.add(new BuDTO(name, buseo.valueOf(bu).getValue(),gen.valueOf(gender).getValue()));
}
catch (IOException e) {
e.printStackTrace();
}
}
for(BuDTO a:list) {
System.out.println(a.toString());
}
}
}
package day25;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
class TeamDTO {
String name;
String team;
public TeamDTO() {}
public TeamDTO(String name, String team) {
super();
this.name = name;
this.team = team;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getTeam() {
return team;
}
public void setTeam(String team) {
this.team = team;
}
@Override
public String toString() {
return "TeamDTO [name=" + name + ", team=" + team + "]";
}
}
public class Test2 {
enum team{ki("KIA타이거즈"), lg("LG트윈스"), lo("롯데자이언츠"), ss("SSG랜더스"), du("두산베어스"),
nc("NC다이노스"), hw("한화이글스"), kw("키움히어로즈"), sa("삼성라이온즈"), kt("kt wiz");
private String value;
private team(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
public static void main(String[] args) throws FileNotFoundException {
ArrayList<TeamDTO> list = new ArrayList<TeamDTO>();
FileReader fr = new FileReader("c:/data/01063.txt");
BufferedReader br = new BufferedReader(fr);
while(true) {
try {
String str = br.readLine();
if(str==null)break;
// String name =str.substring(0, 3);
// String tt =str.substring(3, 5);
// list.add(new TeamDTO(name,team.valueOf(tt).getValue()));
//세터입력방식
TeamDTO dto = new TeamDTO();
dto.setName(str.substring(0, 3));
dto.setTeam(team.valueOf(str.substring(3, 5)).getValue());
list.add(dto);
}
catch (IOException e) {
e.printStackTrace();
}
}
list.forEach(s->System.out.println(s.toString()));
}
}
package day25;
public class TreeDTO {
String bu;
int cost;
public TreeDTO() {}
public TreeDTO(String bu, int cost) {
super();
this.bu = bu;
this.cost = cost;
}
public String getBu() {
return bu;
}
public void setBu(String bu) {
this.bu = bu;
}
public int getCost() {
return cost;
}
public void setCost(int cost) {
this.cost = cost;
}
@Override
public String toString() {
return "TreeDTO [bu=" + bu + ", cost=" + cost + "]";
}
}
package day25;
import java.io.FileNotFoundException;
import java.util.InputMismatchException;
import java.util.Scanner;
public class TreeMenu {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(System.in);
TreeDAO dao = new TreeDAO();
while(true) {
try {
System.out.println("[1]파일입력");
System.out.println("[2]스캐너입력");
System.out.println("[3]출력");
System.out.println("[0]종료");
System.out.print("작업할 번호를 입력");
String nn = sc.next();
int n = Integer.parseInt(nn);
switch (n) {
case 0:System.exit(0);break;
case 1:dao.insert();break;
case 2:dao.insert2();break;
case 3:dao.out();break;
default:break;
}
}
catch(InputMismatchException e) {
System.out.println("문자입력 에러처리");
}
catch(NumberFormatException e) {
System.out.println("문자입력 에러처리");
}
}
}
}
package day25;
import java.util.Scanner;
public class Input {
Scanner sc = new Scanner(System.in);
public String munja(String str) {
System.out.println(str+" 입력");
return sc.next();
}
public int number(String str) {
System.out.println(str+" 입력");
return sc.nextInt();
}
}
package day25;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;
public class TreeDAO {
ArrayList<TreeDTO> list = new ArrayList<TreeDTO>();
enum buseo { i("인사과"),j("자재과"),c("총무과");
private String value;
private buseo(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
public void insert() throws FileNotFoundException {
FileReader fr = new FileReader("c:/data/01064.txt");
BufferedReader br = new BufferedReader(fr);
while(true) {
try {
TreeDTO dto = new TreeDTO();
String str = br.readLine();
if(str==null)break;
dto.setBu(buseo.valueOf(str.substring(0,1)).getValue());
dto.setCost(Integer.parseInt(str.substring(1, 6)));
list.add(dto);
}
catch (IOException e) {
e.printStackTrace();
}
catch (NumberFormatException e) {
System.out.println("문자 입력오류");
}
}
}
public void insert2() {
Input in =new Input();
TreeDTO dto = new TreeDTO();
String bu = in.munja("부서명코드(i,j,c)");
dto.setBu(buseo.valueOf(bu).getValue());
dto.setCost(in.number("매출액"));
list.add(dto);
}
public void out() {
TreeMap<String, Integer> tree = new TreeMap<String, Integer>();
for(int i=0;i<list.size();i++) {
tree.put(list.get(i).getBu(), list.get(i).getCost());
}
Set<String> kset = tree.keySet();
Iterator<String> it = kset.iterator();
System.out.println("부서명\t매출액\n===============");
while(it.hasNext()) {
String aa = it.next();
Integer bb = tree.get(aa);
System.out.println(aa+"\t"+bb);
}
}
}
package day25_Sample1;
import java.text.DecimalFormat;
public class DTO {
DecimalFormat df = new DecimalFormat("#,##0.00");
String name;
int kor,eng,mat;
int tot;
double avg;
String hak;
public DTO() {}
public DTO(String name, int kor, int eng, int mat) {
super();
this.name = name;
this.kor = kor;
this.eng = eng;
this.mat = mat;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getKor() {
return kor;
}
public void setKor(int kor) {
this.kor = kor;
}
public int getEng() {
return eng;
}
public void setEng(int eng) {
this.eng = eng;
}
public int getMat() {
return mat;
}
public void setMat(int mat) {
this.mat = mat;
}
public int getTot() {
return tot;
}
public void setTot(int tot) {
this.tot = tot;
}
public double getAvg() {
return avg;
}
public void setAvg(double avg) {
this.avg = avg;
}
public String getHak() {
return hak;
}
public void setHak(String hak) {
this.hak = hak;
}
@Override
public String toString() {
return "DTO [name=" + name + ", kor=" + kor + ", eng=" + eng + ", mat=" + mat + ", tot=" + tot + ", avg=" + df.format(avg)
+ ", hak=" + hak + "]";
}
}
package day25_Sample1;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Menu {
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(System.in);
DAO dao = new DAO();
while(true) {
System.out.println("[1]입력");
System.out.println("[2]출력");
System.out.println("[0]종료");
System.out.print("작업할 번호를 입력");
String nn = sc.next();
int n = Integer.parseInt(nn);
switch (n) {
case 0:System.exit(0);break;
case 1:dao.insert();break;
case 2:dao.out();break;
default:break;
}
}
}
}
package day25_Sample1;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.ChoiceFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeMap;
public class DAO {
ArrayList<DTO> list = new ArrayList<DTO>();
double [] avg1 = {0,60,70,80,90};
String [] hak1 = {"F","D","C","B","A"};
ChoiceFormat cf = new ChoiceFormat(avg1,hak1);
public void insert() throws FileNotFoundException {
FileReader fr = new FileReader("c:/data/01065.txt");
BufferedReader br = new BufferedReader(fr);
while(true) {
try {
String str = br.readLine();
if(str==null)break;
DTO dto = new DTO();
dto.setName(str.substring(0, 3));
dto.setKor(Integer.parseInt(str.substring(3, 6)));
dto.setEng(Integer.parseInt(str.substring(6, 9)));
dto.setMat(Integer.parseInt(str.substring(9, 12)));
dto.setTot(dto.getKor()+dto.getEng()+dto.getMat());
dto.setAvg((double)dto.getTot()/3);
dto.setHak(cf.format(dto.getAvg()));
list.add(dto);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
public void out() {
TreeMap<String, String> tree = new TreeMap<String, String>();
for(int i=0;i<list.size();i++) {
tree.put(list.get(i).getName(), list.get(i).getHak());
}
Set<String> kset = tree.keySet();
Iterator<String> it = kset.iterator();
System.out.println("이름\t학점\n===============");
while(it.hasNext()) {
String aa = it.next();
String bb = tree.get(aa);
System.out.println(aa+"\t"+bb);
}
}
}
'JAVA' 카테고리의 다른 글
230110_Stream (0) | 2023.01.10 |
---|---|
230109_Stream (0) | 2023.01.09 |
230105_Map (0) | 2023.01.05 |
230104_Map (0) | 2023.01.04 |
230103_Collection (0) | 2023.01.03 |
댓글