package day20_StringTest;
public class StringTest {
public static void main(String[] args) {
String aa = "Iloveyou";
aa = aa.replace("love", "♥");
System.out.println(aa);
aa=aa.concat(" k★rea");
System.out.println(aa);
aa=aa.toUpperCase();
System.out.println(aa);
boolean bb=aa.contains("YOU");
if(bb) {
System.out.println("YOU 문자가 존재합니다.");
}
else {
System.out.println("YOU 문자가 없습니다.");
}
}
}
package day20_StringTest;
public class StringTest {
public static void main(String[] args) {
String aa = " I love you ";
System.out.println(aa);
aa=aa.trim();
System.out.println(aa);
int a=10;
String ab = String.valueOf(a);
System.out.println(ab+ab);
}
}
package day20_StringTest;
public class StringTest {
public static void main(String[] args) {
StringBuffer sb = new StringBuffer();
sb.append("korea");
System.out.println(sb+"\t"+sb.hashCode());
sb.append("iloveyou");
System.out.println(sb+"\t"+sb.hashCode());
sb.delete(5, 10);
System.out.println(sb);
sb.insert(5, "♥");
System.out.println(sb);
sb.replace(0, 6, "ilove");
System.out.println(sb);
int bb = sb.length();
System.out.println(bb);
}
}
package day20_StringTest;
import java.util.Scanner;
public class StringTest {
public static void main(String[] args) {
//회원명단 5명 이름저장
//외부에서 찾는 이름 입력
String sb= "한라산 백두산 설악산 금강산 내장산";
Scanner sc = new Scanner(System.in);
System.out.println("찾으시는 이름을 입력");
String sname = sc.next();
if(sb.contains(sname)) {
System.out.println(sname+"은 명단에 있습니다.");
}
else {
System.out.println(sname+"은 명단에 없습니다.");
}
}
}
package day20_StringTest;
import java.util.Scanner;
public class StringTest {
public static void main(String[] args) {
//회원명단 5명 이름저장
//외부에서 찾는 이름 입력
String [] sb= {"한라산","백두산","설악산","금강산","내장산"};
Scanner sc = new Scanner(System.in);
System.out.println("찾으시는 이름을 입력");
String sname = sc.next();
String bi = null;
for(int i=0;i<sb.length;i++) {
if(sb[i].equals(sname)) {
bi="회원이다";
break;
}
else {
bi="비회원이다";
}
}
System.out.println(bi);
}
}
package day20_StringTest;
import java.util.StringTokenizer;
public class StringTokennizerTest {
public static void main(String[] args) {
String str = "나 보기가 역겨워 가실 때에는 말없이 고이 보내드리오리다";
StringTokenizer st = new StringTokenizer(str," ");
System.out.println("토큰의 수 : "+st.countTokens());
}
}
package day20_Sample2;
class sp {
String spname;
int su,danga,price;
public sp() {}
public sp(String spname, int su, int danga, int price) {
super();
this.spname = spname;
this.su = su;
this.danga = danga;
this.price = price;
}
public String getSpname() {
return spname;
}
public void setSpname(String spname) {
this.spname = spname;
}
public int getSu() {
return su;
}
public void setSu(int su) {
this.su = su;
}
public int getDanga() {
return danga;
}
public void setDanga(int danga) {
this.danga = danga;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}
public class DTO extends sp implements Comparable<DTO>{
String name;
int age;
String address;
public DTO() {}
public DTO(String name, int age, String address) {
super();
this.name = name;
this.age = age;
this.address = address;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
@Override
public String toString() {
return "DTO [name=" + name + ", age=" + age + ", address=" + address + ", spname=" + spname + ", su=" + su
+ ", danga=" + danga + ", price=" + price + "]";
}
public int compareTo(DTO t) {
if(price<t.price) return 1;
else return -1;
}
}
package day20_Sample2;
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.println("원하는 작업 입력");
int n = sc.nextInt();
switch (n) {
case 0:System.exit(0);break;
case 1:dao.insert();break;
case 2:dao.out();break;
}
}
}
}
package day20_Sample2;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
public class DAO {
private SingleTone ston;
public DAO() {
ston=SingleTone.koko();
}
public void insert() throws FileNotFoundException {
FileReader fr = new FileReader("c:/data/12301.txt");
BufferedReader br = new BufferedReader(fr);
while(true) {
try {
DTO dto = new DTO();
String str = br.readLine();
if(str == null)break;
dto.setSpname(str.substring(0, 1));
if(dto.getSpname().equals("a"))dto.setSpname("사과");
if(dto.getSpname().equals("b"))dto.setSpname("바나나");
if(dto.getSpname().equals("m"))dto.setSpname("참외");
dto.setSu(Integer.parseInt(str.substring(1, 3)));
dto.setDanga(Integer.parseInt(str.substring(3, 7)));
dto.setPrice(dto.getSu()*dto.getDanga());
dto.setName(str.substring(7, 10));
dto.setAge(Integer.parseInt(str.substring(10, 12)));
dto.setAddress(str.substring(12));
ston.list.add(dto);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
public void out() {
Collections.sort(ston.out());
for(DTO a:ston.out()) {
System.out.println(a.toString());
}
}
}
package day20_Sample2;
import java.util.ArrayList;
public class SingleTone {
private static SingleTone ston; //객체 선언
ArrayList<DTO> list = new ArrayList<DTO>();
public static SingleTone koko() {
if(ston==null)
ston = new SingleTone();
return ston;
}
public void addin() {
}
public ArrayList<DTO> out() {
return list;
}
}
package day20_Sample1;
class Poom {
String spname;
int su;
int danga;
int price;
public Poom() {}
public String getSpname() {
return spname;
}
public void setSpname(String spname) {
this.spname = spname;
}
public int getSu() {
return su;
}
public void setSu(int su) {
this.su = su;
}
public int getDanga() {
return danga;
}
public void setDanga(int danga) {
this.danga = danga;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}
public class CompanyDTO extends Poom implements Comparable<CompanyDTO>{
String name;
int age;
String address;
public CompanyDTO() {}
public CompanyDTO(String spname, int su, int danga) {}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int compareTo(CompanyDTO t) {
if(price<t.price) return 1;
else return -1;
}
}
package day20_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.println("원하는 작업 입력");
int n = sc.nextInt();
switch (n) {
case 0:System.exit(0);break;
case 1:dao.insert();break;
case 2:dao.out();break;
}
}
}
}
package day20_Sample1;
public class Mamechul {
public int maechul(int su , int danga) {
return su*danga;
}
}
package day20_Sample1;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
public class DAO {
private Singleton ston;
public DAO() {
ston = Singleton.ton();
}
ArrayList<CompanyDTO> list = new ArrayList<CompanyDTO>();
public void insert() throws FileNotFoundException {
FileReader fr = new FileReader("c:/data/12301.txt");
BufferedReader br = new BufferedReader(fr);
while(true) {
try {
CompanyDTO dto = new CompanyDTO();
Mamechul mea = new Mamechul();
String str = br.readLine();
if(str==null)break;
dto.setSpname(str.substring(0, 1));
if(dto.getSpname().equals("a"))dto.setSpname("사과");
if(dto.getSpname().equals("b"))dto.setSpname("바나나");
if(dto.getSpname().equals("m"))dto.setSpname("참외");
dto.setSu(Integer.parseInt(str.substring(1, 3)));
dto.setDanga(Integer.parseInt(str.substring(3, 7)));
dto.setPrice(mea.maechul(dto.getSu(), dto.getDanga()));
dto.setName(str.substring(7, 10));
dto.setAge(Integer.parseInt(str.substring(10, 12)));
dto.setAddress(str.substring(12));
ston.addin(dto);
}
catch (IOException e) {
e.printStackTrace();
}
}
}
public void out() {
DecimalFormat df = new DecimalFormat("#,##0");
System.out.println("상품명\t수량\t단가\t금액\t이름\t나이\t주소");
System.out.print("=======================================");
System.out.println("========================================");
Collections.sort(ston.out());
for(CompanyDTO a:ston.out()) {
System.out.print(a.getSpname()+"\t");
System.out.print(a.getSu()+"\t");
System.out.print(df.format(a.getDanga())+"\t");
System.out.print(df.format(a.getPrice())+"\t");
System.out.print(a.getName()+"\t");
System.out.print(a.getAge()+"\t");
System.out.println(a.getAddress()+"\t");
}
}
}
package day20_Sample1;
import java.util.ArrayList;
public class Singleton {
private static Singleton ston;
ArrayList<CompanyDTO> list = new ArrayList<CompanyDTO>();
public static Singleton ton() {
if(ston==null)
ston = new Singleton();
return ston;
}
public void addin(CompanyDTO dto) {
list.add(dto);
}
public ArrayList<CompanyDTO> out() {
return list;
}
}
'JAVA' 카테고리의 다른 글
230103_Collection (0) | 2023.01.03 |
---|---|
230102_Thread (0) | 2023.01.02 |
221229_SingleTon (0) | 2022.12.29 |
221228_SingleTon (0) | 2022.12.28 |
221227_static (0) | 2022.12.27 |
댓글