?? computefuturetrends.java
字號:
package Osbert;
import java.io.*;
public class ComputeFutureTrends
{
public static void compute () // determines the trendy artists
//
// determine the trendy painters
//
throws IOException {
DataInputStream artFile; // stream object used for file input
boolean found; // indicates if qualified artists were found
String tempFn; // tempFn and tempLn
String tempLn; // stores values read from artist file, namely first name and last name, resp.
found = false;
UserInterface.clearScreen ();
artFile = new DataInputStream(new BufferedInputStream(new FileInputStream("artist.dat")));
//
// read in all paintings from the gallery and
// determine if they are candidates for the trends report
//
while (artFile.available() != 0)
{
//
// read an artist name from the artist file
//
tempFn = artFile.readUTF();
tempLn = artFile.readUTF();;
if(tempFn.length() > 0)
{
//
// check if all of their paintings have sold over the target price
//
if (overTarget (tempFn, tempLn))
{
FutureTrendsReport.printReport (tempFn, tempLn);
found = true;
}
}
} // (inTmp.available() != 0)
artFile.close ();
if (!found)
System.out.println ("There are no artists who qualify for this report...");
System.out.println (); System.out.println ();
System.out.println (" Press <ENTER> to return to main menu...");
UserInterface.pressEnter ();
} // compute
//-------------------------------------------------------------------------------------------------------------------
private static boolean overTarget (String fn, String ln) // determine if a painter has been sold over target
//
// examines all the sold paintings and determines if the artist represented
// by the string parameters fn and ln (first name/last name) has had all of his or her
// paintings sold over the target price during the past year (with at least 2 sales).
// Returns TRUE if all paintings were sold over the target price,
// returns FALSE otherwise
//
throws IOException {
DataInputStream inFile; // stream object used for file input
Date oneLess = new Date(); // date one year ago today
int count; // # of paintings sold over target price
boolean found; // denotes if all paintings sold over target
GalleryPainting tempGallery; // temporary object used for file reading
count = 0;
found = true;
oneLess.parseDate(Date.currentDate.toString());
oneLess.subtractOneYear ();
inFile = new DataInputStream(new BufferedInputStream(new FileInputStream("sold.dat")));
tempGallery = new GalleryPainting();
//
// examine all of the paintings that have been sold
//
while ((inFile.available() != 0) && found)
{
//
// read a temporary gallery object from the sold file
//
tempGallery.readSold (inFile);
//
// ensure that the temporary gallery object is the desired artist
// and that the sale happened within the past year
//
if ((oneLess.compare(tempGallery.getSaleDate ()) <= 0) &&
(UserInterface.compareStr (fn, tempGallery.getFirstName ()) == 0) &&
(UserInterface.compareStr (ln, tempGallery.getLastName ()) == 0))
{
if (tempGallery.getSellPrice () > tempGallery.getTargetPrice ())
count++;
else
found = false;
}
} // ((inFile.available() != 0)) && found)
inFile.close ();
//
// return TRUE iff all paintings sold in the past year were over the target
// price (found == TRUE) and there were at least 2 sales (count > 1)
//
if (found && count > 1)
return true;
else
return false;
} // overTarget
}; // class ComputeFutureTrends
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -