220417
code(java 319p 10번)
import java.util.*;
abstract class Pairmap {
protected String keyArray [];
protected String valueArray [];
abstract String get(String key);
abstract void put(String key, String value);
abstract String delete(String key);
abstract int length();
}
class Dictionary extends Pairmap {
int len;
public Dictionary(int n){
keyArray = new String[n];
valueArray = new String[n];
len=0;
}
String get(String key) {
for(int i = 0;i <len ; i++)
{
if(keyArray[i].equals(key)) return valueArray[i];
}
return null;
}
void put(String key, String value){
keyArray[len]=key;
valueArray[len] = value;
len++;
}
int length() {
return keyArray.length;
}
String delete(String key) {
String delvalue = null;
for(int i = 0;i <len; i++)
{
if(keyArray[i].equals(key)) {
keyArray[i]="";
delvalue=valueArray[i];
valueArray[i]="";
}
}
return delvalue;
}
}
public class Main {
public static void main(String[] args) {
Dictionary dic = new Dictionary(10);
dic.put("황기태" , "JAVA 15");
dic.put("이재문", "PYTHON 3.9");
dic.put("이재문","C++17" );
System.out.println("이재문의 값은 " + dic.get("이재문"));
System.out.println("황기태의 값은 " + dic.get("황기태"));
dic.delete("황기태");
System.out.println("황기태의 값은 " + dic.get("황기태"));
}
}



