/*
* traffic tool
*/
Publicabstract class Transportation {
Private String number;//number
Private String model;//type
Private String admin;//delivery head
Public Transportation () {
Super ();//to omit
}
Public Transportation (String, number, String model, String admin) {
This. Number=number;
This. The model=model;
Enclosing the admin=admin;
}
//transportation method
Publicabstractvoid transport ();
//number
Publicvoid setNumber (String number) {
This. Number=number;
}
Public String getNumber () {
Return the number;
}
//type
Publicvoid setModel (String model) {
This. The model=model;
}
Public String getModel () {
Return the model;
}
//head
Publicvoid setAdmin (String admin) {
Enclosing the admin=admin;
}
Public String getAdmin () {
Return the admin;
}
}
/*
* define maintenance interface, have maintenance function,
*/
Public ninterface Careable {
//maintenance method
Public abstractvoid upKeep ();
}
/*
* special carrier class
*/
Public class ZTransportation extends Transportation implements Careable {
//no arguments structure
Public ZTransportation () {
Super ();
}
//a parameter structure:
, head of the vehicle number, type,Public ZTransportation (String, number, String model, String admin) {
Su per (number, model, admin);
}
//transportation method
Publicvoid transport () {
System. The out. Println (" transportation,,, ");
}
//rewrite vehicle maintenance method
Publicvoid upKeep () {
System. Out.println (" finished goods transport vehicle maintenance!" );
}
}
/*
* Courier class
*/
Public class SendTask {
Private String number;//Courier number
Privatedouble goodsWeight;//cargo weight
Public SendTask () {
Super ();//to omit
}
Public SendTask (String, number, double goodsWeight) {
This. Number=number;
Enclosing goodsWeight=goodsWeight;
}
//send the prepare
Publicvoid sendBefore () {
System. The out. Println (" order start processing, inspection, warehouse, and ");
System. The out. Println (" weight: "+ enclosing getGoodsWeight () +" kg ");
System. Out.println (" the goods inspection!" );
System. Out.println (" finished goods fill!" );
System. Out.println (" shippers have informed!" );
System. The out. Println (" express a single number: "+ enclosing getNumber ());
}
//send the goods
Publicvoid send (Transportation t, GPS tool) {
System. Out.println (" shippers "+ t.g etAdmin ()
Numbers for "+" is driving + t.g etNumber ()
+ "" + t.g etModel () +" to send the goods! ");
T. transport ();
String showCoordinate=tool. ShowCoordinate ();
System. The out. Println (" the goods are the coordinates of the current: "+ showCoordinate);
}
//send operation after
Publicvoid sendAfter (Transportation t) {
System. Out.println (" cargo transportation task has been completed! ");
System. Out.println (" shippers "+ t.g etAdmin ()
The Numbers for "+" was in + t.g etNumber ()
+ "" + t.g etModel () +" has returned! ");
}
Public String getNumber () {
Return the number;
}
Publicvoid setNumber (String number) {
This. Number=number;
}
Publicdouble getGoodsWeight () {
Return goodsWeight;
}
Publicvoid setGoodsWeight (double goodsWeight) {
Enclosing goodsWeight=goodsWeight;
}
}
/*
* GPS interface definition, have GPS function,
*/
Public interface GPS {
//display coordinate method
Public String showCoordinate ();
}
/*
* define an item at random, the realization of GPS interface, with positioning function,
*/
The class Phone implements GPS {
Public Phone () {//short and construct
Super ();
}
//locating method
Public String showCoordinate () {
The String location="193485";
Return the location;
}
}/*
* define the test class
*/
Public class Task02Test {
Publicstaticvoid main (String [] args) {
//Courier class object
SendTask task=new SendTask (" HYX600235 ", 76.34);
//call send preparation method
Task. SendBefore ();
System. The out. Println ("======================");
//create transport object
ZTransportation t=new ZTransportation (" Z025 ", "big rush", "han provided");
//create GPS tool object
Phone p=new Phone ();
//vehicles with GPS tools into the delivery method
Task. The send (t, p);
System. The out. Println ("======================");
//call send after operation method
Task. SendAfter (t);
T.u pKeep ();
}
}
CodePudding user response:
FileWriter fw=new FileWriter (" F: \ \ a.t xt ", true);//F: \ \ a.t xt file location forBufferedWriter bw=new BufferedWriter (fw);
Bw. Write (data);//data for you to write TXT data, type String
bw.close();
fw.close();
CodePudding user response:
If you just want to print the results to the TXT in reference 1 floor, if you want to print to the console display information in the TXT, can use the CMD way to run a Java program, and then the content of the print is redirected to the new TXT file, 1. To compile the first class javac class name. Java, generates a class file, (2) execute Java class file name (don't add the suffix) & gt; Test. TXT, such console information content will be printed to the test. The TXT file