import java.io.FileInputStream;
import java.io.InputStream;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
public class Properties implements Serializable
{
private int time=100;
private int speed=10;
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public static void main(String[] args) throws Exception{
Properties p = new Properties();
OutputStream out = new FileOutputStream("d:/test.txt");
ObjectOutputStream os = new ObjectOutputStream(out);
os.writeObject(p);
os.close();
}
}
import java.io.ObjectInputStream;
import java.io.Serializable;
public class Test {
private static final double GRAVITY = 9.8; //重力加速度
public double getDisplacement(int speed,int time ){//根据公式得到
位移
return time*time*GRAVITY/2+speed*time;
}
public static void main(String[] args) throws Exception{
Test test = new Test();
InputStream in = new FileInputStream("d:/test.txt");
ObjectInputStream os = new ObjectInputStream(in);
Properties p = (Properties)os.readObject();
os.close();
System.out.println(test.getDisplacement(p.getSpeed(),p.
getTime()));
}
}
C:\Users\Administrator\Desktop\Properties implements Serializable.java:31: 'class' or 'interface' expected
import java.io.ObjectInputStream;
^
C:\Users\Administrator\Desktop\Properties implements Serializable.java:32: 'class' or 'interface' expected
import java.io.Serializable;
^
C:\Users\Administrator\Desktop\Properties implements Serializable.java:36: not a statement
位移
^
C:\Users\Administrator\Desktop\Properties implements Serializable.java:37: ';' expected
return time*time*GRAVITY/2+speed*time;
^
4 errors 工具以退出代码 1 完成
import java.io.InputStream;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
public class Properties implements Serializable
{
private int time=100;
private int speed=10;
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
}
public int getSpeed() {
return speed;
}
public void setSpeed(int speed) {
this.speed = speed;
}
public static void main(String[] args) throws Exception{
Properties p = new Properties();
OutputStream out = new FileOutputStream("d:/test.txt");
ObjectOutputStream os = new ObjectOutputStream(out);
os.writeObject(p);
os.close();
}
}
import java.io.ObjectInputStream;
import java.io.Serializable;
public class Test {
private static final double GRAVITY = 9.8; //重力加速度
public double getDisplacement(int speed,int time ){//根据公式得到
位移
return time*time*GRAVITY/2+speed*time;
}
public static void main(String[] args) throws Exception{
Test test = new Test();
InputStream in = new FileInputStream("d:/test.txt");
ObjectInputStream os = new ObjectInputStream(in);
Properties p = (Properties)os.readObject();
os.close();
System.out.println(test.getDisplacement(p.getSpeed(),p.
getTime()));
}
}
C:\Users\Administrator\Desktop\Properties implements Serializable.java:31: 'class' or 'interface' expected
import java.io.ObjectInputStream;
^
C:\Users\Administrator\Desktop\Properties implements Serializable.java:32: 'class' or 'interface' expected
import java.io.Serializable;
^
C:\Users\Administrator\Desktop\Properties implements Serializable.java:36: not a statement
位移
^
C:\Users\Administrator\Desktop\Properties implements Serializable.java:37: ';' expected
return time*time*GRAVITY/2+speed*time;
^
4 errors 工具以退出代码 1 完成