제가하고 있던 것은 기타의 이름을 입력 할 때 몸의 모양, 프렛 수 등과 같은 몇 가지 사양이 표시되는 것입니다.
그래서 메인 코딩 클래스를 만들었습니다.
package Guitar;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Input name of the guitar");
Scanner name_g = new Scanner(System.in);
String name_gf = name_g.next();
Gibson g = new Gibson();
System.out.println("Body Shape of the Guitar is : ");
g.body_shape(name_gf);
System.out.println("Number of frets of the Guitar is : ");
g.num_frets(name_gf);
System.out.println("Neck type of the guitar is : ");
g.neck_type(name_gf);
System.out.println("Pickup configuration of the guitar is : ");
g.pup_conf(name_gf);
}
}
깁슨 기타에 특화된 다른 클래스
package Guitar;
public class Gibson extends SpecsVar implements SpecsInterface {
@Override
public String body_shape(String input) {
// TODO Auto-generated method stub
System.out.println("Body shape of the guitar is : ");
if (input.equals(lp)){
return lp;}
else if (input.equals(ex)){
return ex;}
else if (input.equals(sg)){
return sg;}
else return "invalid Input.";
}
@Override
public String num_frets(String input) {
// TODO Auto-generated method stub
if (input.equals(lp)){
return shrt_fret;}
else if (input.equals(ex)){
return shrt_fret;}
else if (input.equals(sg)){
return shrt_fret;}
else return "";
}
@Override
public String neck_type(String input) {
// TODO Auto-generated method stub
if (input.equals(lp)){
return mh;}
else if (input.equals(ex)){
return rw;}
else if (input.equals(sg)){
return rw;}
else return "";
}
@Override
public String pup_conf(String input) {
// TODO Auto-generated method stub
if (input.equals(lp)){
return hh;}
else if (input.equals(ex)){
return hh;}
else if (input.equals(sg)){
return hh;}
else return "";
}
}
그런 다음 사양 클래스가
package Guitar;
public class SpecsVar {
//Body Shape
String lp = "Les Paul";
String ex = "Explorer";
String sg = "SG";
//Number of Frets
String shrt_fret = "22";
String lng_fret = "24";
//Neck Type
String rw = "Rosewood";
String mp = "Maple";
String mh = "Mahogany";
//Pickup Configuration
String hsh = "HSH";
String sss = "SSS";
String hss = "HSS";
String hh = "HH";
}
그런 다음 인터페이스
package Guitar;
public interface SpecsInterface {
String body_shape(String input);
String num_frets(String input);
String neck_type(String input);
String pup_conf(String input);
}
무슨 일이 일어나고 있는지
Input name of the guitar
Gibson
Body Shape of the Guitar is :
Body shape of the guitar is :
Number of frets of the Guitar is :
Neck type of the guitar is :
Pickup configuration of the guitar is :
달릴 때 프렛 수, 몸매 등이 안나와요.
당신에 System.out.println()
당신은이 일을하고 있습니다 :
System.out.println("Body Shape of the Guitar is : ");
g.body_shape(name_gf);
통화 g.body_shape(name_gf);
로 이동 System.out.println()
하고 나머지 모든 통화에 대해 동일하게 수행하십시오. 이것을 문자열 연결 이라고합니다.
System.out.println("Body Shape of the Guitar is : " + g.body_shape(name_gf));
이것은 System.out.println()
실제로 화면에 인쇄되는 것이지만 두 번째 부분 g.body_shape(name_gf);
은 검색 만 수행하고 다른 작업은 수행하지 않았기 때문에 발생하므로 인쇄 호출에 입력해야했습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다