JAVA/응용문제

[영어단어장 프로그램 만들기]

java나유 2022. 7. 5. 16:16
public class t0704_q {
	public static void main(String[] args) {
		/*
		 * [TEST1] 영어단어장 프로그램을 제작해야 합니다. 다음과 같은 예제를 활용합니다.
		 * 
		 * 1.입력 2.검색 3.가장 긴 단어찾기 > 1 > 영어단어 : apple > 한국어 : 사과
		 * 
		 * 1.입력 2.검색 3.가장 긴 단어찾기 > 1 > 영어단어 : banana > 한국어 : 바나나
		 * 
		 * 1.입력 2.검색 3.가장 긴 단어찾기 > 1 > 영어단어 : kiwi > 한국어 : 키위
		 * 
		 * 1.입력 2.검색 3.가장 긴 단어찾기 > 2 > kiwi > 키위
		 * 
		 * 1.입력 2.검색 3.가장 긴 단어찾기 > 2 > 키위 > kiwi
		 * 
		 * 1.입력 2.검색 3.가장 긴 단어찾기 > 3 > banana
		 * 
		 * 다음과 같이 작동되는 프로세서를 제작하시오. 2. 검색은 한글, 영문 모두 검색이 되어야 합니다. 3. 가장 긴 단어찾기는 무조건 영어로만
		 * 검색이 됩니다. 해당 각 파트별(1,2,3) 선택에 따른 메소드는 별도로 분리하여 코드를 제작되도록 합니다.
		 */
	
		lipton ip = new lipton();
		ip.use();
	}
}
class lipton{
	
	static ArrayList<String> Kor = new ArrayList();
	static ArrayList<String> Eng = new ArrayList();
	Scanner sc = new Scanner(System.in);
	//public static void useruser() {
		
	int user;
	String name;

	public void use() {
		System.out.println("1.입력 2.검색 3.가장 긴 단어찾기");
		user=sc.nextInt();
		if(this.user==1) {
		 no_1();
	
		}
		else if(this.user==2) {
			no_2();
		}
	
		else if(this.user==3) {
			no_3();
		}
	}	
	public void no_1() {
		System.out.println("단어를 입력해주세요 영어");
		String user2=sc.next();
		Eng.add(user2);
		System.out.println("단어를 입력해주세요 한국어");
		String user3=sc.next();
		Kor.add(user3);
		use();
		//System.out.println(Eng);
		//System.out.println(Kor);
	}
	
	public void no_2() {
		System.out.println("검색할 단어를 입력해주세요");
		String user4=sc.next();
		for(int i=0; i<Kor.size();i++) {
			//for(int a=0;a<Eng.size();a++) {
			
				if(user4.equals(Kor.get(i))) {
					System.out.println(Eng.get(i));
					use();
					}
				else if (user4.equals(Eng.get(i))){
					System.out.println(Kor.get(i));
					use();
				}
			}
		}
		//no_3();
	
	public void no_3() {
		String wordlong="";
		int max =0;
		for(int h=0;h<this.Eng.size();h++) {
			this.name=Eng.get(h);
			if(max<name.length()) {
				max=name.length();
				wordlong=name;
				
				
			}
		}
		System.out.println("가장 긴 단어는??"+this.name);
		use();
	}
	
}

결과 값

728x90