📄 computemasterpieceprice.java
字号:
package Osbert;
import java.io.*;
public class ComputeMasterpiecePrice
{
private static double ANNUAL_INTEREST = 1.085;
// determines the maximum price to be offered for a masterpiece
public static double getAlgorithmPrice (GalleryPainting masterpiece)
throws IOException {
DataInputStream inFile;// stream object used for file input
double high;// keeps track of highest similarity
double algHigh;// price of most similar work
double temp;// number of matches on medium/subject
double auctionArea;// area of an auction painting
double galleryArea;// area of a gallery painting
int i; // loop iterator for compound interest
Date highDate; // date of most similar work
AuctionedPainting tempAuction; // temporary object used for file reading
high = 0.0;
algHigh = 0.0;
highDate = Date.currentDate;
inFile = new DataInputStream(new BufferedInputStream(new FileInputStream("auction.dat")));
tempAuction = new AuctionedPainting();
// loop through all of the auction objects and find the most similar work
while (inFile.available() != 0)
{
//
// read an auction object
//
tempAuction.readAuctionData (inFile);
temp = 0.0;
//
// if the artist names match, compute the similarity
//
if ((UserInterface.compareStr (tempAuction.getFirstName (), masterpiece.getFirstName()) == 0) &&
(UserInterface.compareStr (tempAuction.getLastName (), masterpiece.getLastName()) == 0))
{
if (masterpiece.getMedium().compareTo(tempAuction.getMedium ()) == 0)
temp++;
if (masterpiece.getSubject().compareTo(tempAuction.getSubject ()) == 0)
temp++;
auctionArea = tempAuction.getHeight () * tempAuction.getWidth ();
galleryArea = masterpiece.getHeight() * masterpiece.getWidth();
if (auctionArea > galleryArea)
temp = temp * galleryArea / auctionArea;
else
temp = temp * auctionArea / galleryArea;
//
// a higher similarity was found...
//
if (temp > high)
{
high = temp;
algHigh = tempAuction.getAuctionPrice ();
highDate = tempAuction.getAuctionDate ();
}
} // if ((compareStr (tempAuction.getFirstName (), firstName) == 0)
} // while (inFile.available() != 0)
inFile.close ();
//
// compute the compound interest
//
for (i = highDate.getYear(); i < Date.currentDate.getYear(); i++)
algHigh = algHigh * ANNUAL_INTEREST;
return algHigh;
} // getAlgorithmPrice
} // class ComputeMasterpiecePrice
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -