import java.io.BufferedReader; 가져 오기 java.io.InputStreamReader;Java에서 들어오는 인수로 변수를 설정하는 방법은 무엇입니까?
공용 클래스 Problem3_1 {
//complete this class, called Problem3_1, with the following items:
//1. Declare four attributes, name, age, height, and weight of types String and int-s.
//Write a constructor for this class that initializes ONLY the name, age, and height to three incoming arguments,
//and sets the weight to always be -1 (the latter is not an incoming argument).
String name;
int age;
int height;
int weight;
Address address;
public Problem3_1(String name, int age, int height) {
this.name = name;
this.age = age;
this.height = height;
weight = -1;
}
void setAddress(int number, String street) {
address = new Address(number, street);
}
//2. Imagine there is a class called Address that you have access to (it's below).
//Its constructor takes an integer street number and a String street. Add an attribute called address to
//the Problem3_1 class, and create a method called setAddress that sets the attribute to the incoming argument.
public static class Address{
int number;
String street;
public Address(int number, String street){
this.number = number;
this.street = street;
}
}
}
아래 템플릿이 왜 코드가 내가 잘못된 위치에서이 공간 정보를 말하는 // COMPLETE? 올바른 위치는 어디입니까? 아니면 "적용"할 수없는 이유는 무엇입니까?
PS :이 오류는 내가 얻을 :
Problem3_1.java:82: setAddress(int,java.lang.String) in Problem3_1 cannot be applied to (Problem3_1.Address) p.setAddress(a);
테스트 케이스 :
public static void main(String[] args){
/*Below are tests that will check if you completed the code above correctly; if
your code doesn't compile, you'll need to fix those errors first.
DO NOT WRITE CODE BELOW THIS POINT
*/
int failed = 0;
Problem3_1 p = new Problem3_1("Jane", 22, 65);
if (p.name.compareTo("Jane") == 0 && p.age == 22 && p.height == 65 && p.weight == -1)
System.out.println("Test 1 passed!");
else{
failed ++;
System.out.println("Please check your code for question 1! ");
}
Address a = new Address(12, "Fairfax Dr");
p.setAddress(a);
if (p.address == a)
System.out.println("Test 2 passed!");
else{
failed ++;
System.out.println("Please check your code for question 2! ");
}
if (failed > 0)
System.out.println(systemCall("Failed"));
else{
System.out.println("GREAT WORK! EVERYTHING PASSED!");
System.out.println(systemCall("Nice"));
}
}
당신은 setAdress 함수에서 매개 변수를 잊어 버렸습니다. – Marko