Lab4-Plural
5530244621 นายธนาวัฒน์ สิทธิสันติกุล (COM21900) (12/18/2012 (12:19:06 PM))
MiniQuiz + TestScript |
JLab>java Selftest
JLab> testPlural : ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok ok (10.0/10.0)
JLab> : -----------------------------
JLab> : ?????? 10.0 ????? (???? 10.0)
JLab> : -----------------------------
JLab> :<POINT>10.0</POINT> (<TOTAL>10.0</TOTAL> )
JLab>
ได้ 10 คะแนน |
Source Code |
import java.util.Scanner;
public class Plural {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
System.out.print("singular noun = ");
String s = kb.next();
String p = "";
int type = 0;
int l = s.length();
String s1 = s.trim().toLowerCase();
String chk = s1.substring(l - 2);
String chk2 = s1.substring(l - 1);
String chk3 = s1.substring(l - 2, l - 1);
String a = "aeoiu";
if (a.indexOf(chk3) == -1) {
if (chk2.equals("s")) type = 1;
if (chk2.equals("x")) type = 1;
if (chk.equals("ch")) type = 1;
if (chk2.equals("y")) type = 2;
} else {
if (chk2.equals("s")) type = 1;
if (chk2.equals("x")) type = 1;
if (chk.equals("ch")) type = 1;
}
/* String chk = s.trim().toLowerCase().substring(l - 2, l - 1);
String chk2 = s.trim().toLowerCase().substring(l - 2, l);
if (chk.indexOf("a")==-1||chk.indexOf("e")==-1||chk.indexOf("i") == -1 ||chk.indexOf("o") == -1 ||chk.indexOf("u")==-1) {
if (chk.equals("s")) {
type = 1;
}
if (chk.equals("x")) {
type = 1;
}
if (chk2.equals("ch")) {
type = 1;
}
} else {
if (chk.equals("y")) {
type = 2;
}
}*/
if (type == 0) {
p = s + "s";
}
if (type == 1) {
p += s + "es";
}
if (type == 2) {
p += s.substring(0, l - 1) + "ies";
}
System.out.println("plural = " + p);
}
}
|
SM=4, CM=68, ST=67, KY=3549, TR=60:00
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
ERR = 60:00 ;
|
|