以下为参考书本以及一些帖子,写下的构建方法的程序。小白课程中刚学会构建方法并进行初始化,作业要求构建方法显示数据并使用该方法初始化。此前出错预览了一些帖子,修改过构建方法中的类型,但是一直出错,求大佬帮忙看看。
以下为版本1
//Object.java
//21/04/11
import javax.swing.JOptionPane;
//method to present the detail
class ObjectStore{
String output;
public void code(){
ouput = JOptionPane.showMessageDialog(null,"a bike with marked code is 19")
}
public void address(){
ouput + = "owned by the person who lives at 14 King Road"
}
public void district(){
ouput += "which is in police district 10"
}
public void show(){
JOptionPane.showMessageDialog(null,output, "The bike message" , JOptionPane.PLAIN_MESSAGE);
}
}
//end the method to present the detail
}
public class Object{
public static void main(String arg[]){
ObjectStore BikeInformation = new ObjectStore().show;
}
//end the main method
}
//end the class Object
//Object.java
//21/04/11
import javax.swing.JOptionPane;
//method to present the detail
class ObjectStore{
String Code;
String Address;
int District;
public String setcode(String A){
this.Code = A;
return Code;
}
public int setdistrict(int B){
this.District= B;
return District;
}
public String setaddress(String C){
this.Address= C;
return Address;
}
//end the method to present the detail
}
class TEST{
public static void main(String arg[]){
ObjectStore BikeInformation = new ObjectStore();
ObjectStore.setcode("AXB");
ObjectStore.setdistrict(19);
ObjectStore.setaddress("14 Kings Road");
JOptionPane.showMessageDialog(null,"a bike with marked code" +BikeInformation. Code + "owned by the person who lives at"
+ BikeInformation.Address + ",which is in police distric"
+ BikeInformation.District," The bike message ", JOptionPane.PLAIN_MESSAGE);
}
//end the main method
}
//end the class Object