誰かが私を助けてくれませんか.propと呼ばれる配列リストを、それが宣言され、オブジェクトを追加したifステートメントの外で使用しようとしています.
これがif文です。コードはユーザーに情報を入力するように要求し、次に、作成したプロパティ オブジェクトを ArrayList に追加する場所で、Property オブジェクトとプロパティの ArrayList が宣言されます。
if(option.equals("one")){
int x = 1;
do{
try{
System.out.println("Enter owner name");
String ownerName = scan.nextLine();
System.out.println("Enter address");
String address = scan.nextLine();
System.out.println("Are you the principle private residant?");
String principlePrivateResidance = scan.nextLine();
System.out.println("Enter property location(city, large town, small town, vilage, countryside) ");
String location = scan.nextLine();
System.out.println("would you like to pay the propery tax now?(yes//no)");
String paid = scan.nextLine();
System.out.println("Enter your filename");
String fn = scan.nextLine();
System.out.println("Enter the estimated property value");
int propertyEstimatedVal = scan.nextInt();
// i make the object here
Property property = new Property(ownerName, address, paid, principlePrivateResidance,location, propertyEstimatedVal);
// Then make the arraylist and add the object to it take this arraylist and put it....
ArrayList<Property> prop = new ArrayList<Property>;
prop.add(property);
CalculateTax tax = new CalculateTax(property.getLocation(),property.getPrinciplePrivateResidance(),property.getPropertyEstimatedVal(), property.getPaid());
System.out.println("owner:" + property.getOwnerName());
System.out.println("address:" +property.getAddress());
System.out.println("propertyEstimatedVal:" +property.getPropertyEstimatedVal());
System.out.println("principlePrivateResidance:" +property.getPrinciplePrivateResidance());
System.out.println("location:" +property.getLocation());
System.out.println("paid:" +property.getPaid());
System.out.println("Your property tax is" + CalculateTax.getSumoftax() );
System.out.println("your details have been taken");
FileWriter fstream = new FileWriter(fn,true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(property.getOwnerName() + " | " + property.getAddress() + " | " + property.getPropertyEstimatedVal() + " | " + property.getPrinciplePrivateResidance() + " | " + property.getLocation() + " | " + property.getPaid() + " | " + CalculateTax.getSumoftax());
out.newLine();
out.close();
x= 2;
}
catch(Exception e){
System.out.println("error has occured");
}
}
while(x == 1);
}
else if(option.equals("two")){
// this just opens a file
System.out.println("Please enter you file name");
String filename = scan.nextLine();
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream(filename);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}
catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
else if(option.equals("three")){
//i need to get that arraylist with the objects i added to it here but
//i just dont know how
System.out.print("Service is currently available ");
}
else{
System.exit(0);
}