⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 auctionedpainting.java

📁 该程序有17个java源文件。是经典奥斯波特艺术品商人软件工程例子
💻 JAVA
字号:
package Osbert;
import java.io.*;


public class AuctionedPainting extends Painting
{

  protected	Date	auctionDate;	// date painting sold at auction
  protected double	auctionPrice;	// auction price of painting

  // getters-setters for AuctionedPainting
  public Date getAuctionDate ()		    { return auctionDate; }
  public void setAuctionDate (Date d)   { auctionDate = d; }
  public double getAuctionPrice ()		{ return auctionPrice; }
  public void setAuctionPrice (double p) { auctionPrice = p; }

  public void readAuctionData (DataInputStream fileName)	// stream object where auction information is read
  //
  //     reads an auction object from fileName
  //     Note: Java serialization could be used as an alternative to this approach
  //
  throws IOException {
	String tempDate;

	firstName = fileName.readUTF();
	lastName = fileName.readUTF();
	title = fileName.readUTF();
	tempDate = fileName.readUTF();
	paintingDate = new Date();
	paintingDate.parseDate(tempDate);
	height = fileName.readDouble();
	width = fileName.readDouble();
	medium = fileName.readUTF();
	subject = fileName.readUTF();
	tempDate = fileName.readUTF();
	auctionDate = new Date();
	auctionDate.parseDate(tempDate);

	auctionPrice = fileName.readDouble();

  } // readAuctionData

  public void writeAuctionData (DataOutputStream fileName)	// stream object where auction information is read
  //
  //     reads an auction object from fileName
  //     Note: Java serialization could be used as an alternative to this approach
  //
  throws IOException {

	fileName.writeUTF(firstName);
	fileName.writeUTF(lastName);
	fileName.writeUTF(title);
	fileName.writeUTF(paintingDate.toString());
	fileName.writeDouble(height);
	fileName.writeDouble(width);
	fileName.writeUTF(medium);
	fileName.writeUTF(subject);
	fileName.writeUTF(auctionDate.toString());
	fileName.writeDouble(auctionPrice);

  }
  //*** remove later

  AuctionedPainting() { }

  AuctionedPainting(String f, String l, String t, String pd, double h, double w, String m, String s, String ad, double pr )
  {
    firstName = f;
    lastName = l;
    title = t;
    paintingDate = new Date();
    paintingDate.parseDate(pd);
    height = h;
    width = w;
    medium = m;
    subject = s;
    auctionDate = new Date();
    auctionDate.parseDate(ad);
    auctionPrice = pr;
  }


  public void createAuction()
  throws IOException {

   AuctionedPainting a1 = new AuctionedPainting("Leonardo", "da_Vinci", "Lisa", "01/01/1530",
                                               82.5, 30.9, "oil", "portrait", "11/20/1970", 43.4);

   AuctionedPainting a2 = new AuctionedPainting("Rembrandt", "Hermensz", "Supper_At_Emmaus", "01/01/1650",
												90.7, 41.3, "watercolor", "still", "03/16/1963", 13.6);

   AuctionedPainting a3 = new AuctionedPainting("Jean", "Watteau", "Embarkation_for_Cythera", "01/01/1705",
                                               103.3, 61.7, "oil", "landscape", "04/22/1986", 23.4);

   AuctionedPainting a4 = new AuctionedPainting("Jacques", "David", "The_Death_of_Marat", "01/01/1805",
                                               43.6, 51.4, "watercolor", "still", "01/04/1952", 1.1);

   AuctionedPainting a5 = new AuctionedPainting("Honore", "Daumier", "The_Rue_Transonian", "01/01/1815",
                                               52.5, 51.6, "oil", "still", "07/06/1973", 2.3);

   AuctionedPainting a6 = new AuctionedPainting("Pierre", "Renoir", "The_Luncheon_of_the_Boating_Party", "01/01/1875",
                                               134.2, 89.9, "watercolor", "landscape", "10/31/1984", 6.1);

   AuctionedPainting a7 = new AuctionedPainting("Pablo", "Picasso", "Guernica", "01/01/1930",
                                               94.1, 31.6, "watercolor", "other", "05/29/1990", 20.4);

  a1.addToFile();
  a2.addToFile();
  a3.addToFile();
  a4.addToFile();
  a5.addToFile();
  a6.addToFile();
  a7.addToFile();

/*
    for(int i = 1; i < 8; i++)
    {


      String dateStr = new String();

      System.out.print("First: ");
	  firstName = UserInterface.getString();
	  System.out.print("Last: ");
	  lastName = UserInterface.getString();
	  System.out.print("Title: ");
	  title = UserInterface.getString();

	  System.out.print("Painting Date: ");
	  dateStr = UserInterface.getString();
	  paintingDate = new Date();
 	  paintingDate.parseDate(dateStr);

	  System.out.print("Height: ");
	  height = UserInterface.getDouble();
	  System.out.print("Width: ");
	  width = UserInterface.getDouble();
	  System.out.print("Medium: ");
      medium = UserInterface.getString();
	  System.out.print("Subject: ");
      subject = UserInterface.getString();

	  System.out.print("Auction Date: ");
	  dateStr = UserInterface.getString();
	  auctionDate = new Date();
	  auctionDate.parseDate(dateStr);

	  System.out.print("Auction price: ");
	  auctionPrice = UserInterface.getDouble();

      addToFile();

    }
*/

  }

  public void addToFile()
  throws IOException {

	DataInputStream inTmp = new DataInputStream(new BufferedInputStream(new FileInputStream("auction.dat")));
	DataOutputStream outTmp = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("tempA.dat")));
	AuctionedPainting tempAuction = new AuctionedPainting();

	//
	// copy the current fashionability file to a temporary file
	//
	while (inTmp.available() != 0)
	{

	  //
	  // read/write a temporary object from the fashionability file
	  //
	  tempAuction.readAuctionData (inTmp);
	  tempAuction.writeAuctionData (outTmp);

	} // while (inTmp.available() != 0)

	outTmp.close ();
	inTmp.close ();

	DataInputStream inCpy = new DataInputStream(new BufferedInputStream(new FileInputStream("tempA.dat")));
	DataOutputStream outCpy = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("auction.dat")));

	while (inCpy.available() != 0)
	{

	  //
	  // read/write a temporary fashionability object from the temporary file
	  //
	  tempAuction.readAuctionData (inCpy);
  	  tempAuction.writeAuctionData (outCpy);

    }

    writeAuctionData (outCpy);

    outCpy.close ();
    inCpy.close ();

  }

}; // class AuctionedPainting

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -