我搜索了几个不同的帖子,但我们找不到确切的问题。我觉得我所缺少的东西应该是非常明显的,但由于某种原因,不能确定它已经玩了一切,但不能得到它。如果有人能帮助我,我将不胜感激。该程序旨在从文本文件中提取房屋信息并输出。 JMUnit7文件由教师提供给我们。 JMUnit7House文件是我的工作。提前致谢。
package jmunit7;
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
/**
*
* @author Xephus
*/
public class JMUnit7 {
/**
* @param args the command line arguments
* @throws java.lang.Exception
*/
public static void main(String[] args) throws Exception
{
Scanner stdIn = new Scanner(System.in);
Scanner stdInFile = new Scanner(new
File("JMUnit7House.txt"));
JMUnit7House house1, house2; //New houses
//Create house 1 using default constructor
house1 = new JMUnit7House();
house1.print(); //print house 1 with default values
String street, city, state, zipCode;
int number;
System.out.println("Importing Number.");
number = stdInFile.nextInt();
stdInFile.nextLine();
System.out.println("Importing Street.");
street = stdInFile.nextLine();
System.out.println("Importing City.");
city = stdInFile.nextLine();
System.out.println("Importing State.");
state = stdInFile.nextLine();
System.out.println("Importing ZipCode.");
zipCode = stdInFile.nextLine();
System.out.println();
//use method call chaining to set values
//and print results for house 1
house1.setNumber(number).setStreet(street)
.setCity(city).setState(state)
.setZipCode(zipCode).print();
System.out.println("Importing Number.");
number = stdInFile.nextInt();
stdInFile.nextLine();
System.out.println("Importing Street.");
street = stdInFile.nextLine();
System.out.println("Importing City.");
city = stdInFile.nextLine();
System.out.println("Importing State.");
state = stdInFile.nextLine();
System.out.println("Importing ZipCode.");
zipCode = stdInFile.nextLine();
System.out.println();
//create house 2 using 5 parameter constructor
house2 = new JMUnit7House(number,
street, city, state, zipCode);
//print house 2
house2.print();
}
}
我的代码如下获取和错误的sym类型错误,即:线程中的异常" main" java.lang.RuntimeException:无法编译的源代码 - 错误的sym类型:.setCity.setState.setZipCode.print at jmunit7.JMUnit7.main(JMUnit7.java:49)49是house1.setNumber行。
public class JMUnit7House {
private int number;
private String street;
private String city;
private String state;
private String zipCode;
public JMUnit7House()
{
number = 0;
street = "No Street";
city = "No City";
state= "No State";
zipCode = "No Zip Code";
}
//intializes house with arguments
public JMUnit7House(int number, String street, String city, String state, String zipCode)
{
this.number = number;
this.street = street;
this.city = city;
this.state = state;
this.zipCode = zipCode;
}
public int setNumber(int number)
{
return number;
}
public String setStreet(String street)
{
return street;
}
public String setCity(String city)
{
return city;
}
public String setState(String state)
{
return state;
}
public String setZipCode(String zipCode)
{
return zipCode;
}
//function to print
public void print()
{
String info=String.format("House: %d\n", number);
info += String.format("Street: %s\n", street);
info += String.format("City: %s\n", city);
info += String.format("State: %s\n", state);
info += String.format("Zip: %s\n", zipCode);
System.out.println(info);
}
}