?? purchasesreport.java
字號:
package Osbert;
import java.io.*;
public class PurchasesReport
{
public static void printReport () // displays a report of bought paintings
//
// displays a report of bought paintings
//
throws IOException {
DataInputStream inFile; // stream object used for file input
Date oneLess = new Date(); // date one year ago today
int i; // counts number of paintings in report
double totalPurchase; // sum of actual purchase prices
double totalMax; // sum of maximum purchase prices
GalleryPainting tempGallery; // temporary object used for file reading
totalPurchase = 0.0;
totalMax = 0.0;
i = 0;
UserInterface.clearScreen ();
oneLess.parseDate(Date.currentDate.toString());
oneLess.subtractOneYear();
inFile = new DataInputStream(new BufferedInputStream(new FileInputStream("gallery.dat")));
tempGallery = new GalleryPainting();
//
// read in all paintings from the gallery and
// determine if they are candidates for the bought report
//
while (inFile.available() != 0)
{
//
// read a gallery object from the gallery file
//
tempGallery.readBought (inFile);
//
// check if the painting was purchased within the past year
//
if (oneLess.compare(tempGallery.getPurchaseDate()) <= 0)
{
//
// pause the screen after every three paintings
//
if (((i % 3) == 0) && (i != 0))
{
System.out.println("\n\n Press <ENTER> to view the next screen...");
UserInterface.pressEnter (); UserInterface.pressEnter ();
}
//
// display a header message after every third painting
//
if ((i % 3) == 0)
{
UserInterface.clearScreen ();
System.out.println("\n\n\t\t Report Date: " +Date.currentDate);
System.out.println("\t\t Osbert Oglesby - Collector of Fine Art");
System.out.println("\t\t BOUGHT PAINTINGS\n");
}
System.out.println("--------------------------------------------------------------------------");
System.out.print("CLASSIFICATION: ");
if (tempGallery.getPurchasePrice() > tempGallery.getAlgPrice())
System.out.print("*");
System.out.print(tempGallery.getClassification() + " ");
System.out.println("\tPURCHASE DATE: " + tempGallery.getPurchaseDate());
System.out.print("LAST NAME: " + tempGallery.getLastName());
System.out.println("\t\tTITLE: " + tempGallery.getTitle());
System.out.print("SUGG. PRICE: " + tempGallery.getAlgPrice());
System.out.println("\t\tPURCHASE PRICE: " + tempGallery.getPurchasePrice());
totalPurchase = totalPurchase + tempGallery.getPurchasePrice();
totalMax = totalMax + tempGallery.getAlgPrice();
i++;
} // if (dateCompare (oneLess, purchaseDate) <= 0)
} // while (inFile.available() != 0)
inFile.close ();
if (totalMax > 0)
System.out.println("\n\nAverage ratio: " + (totalPurchase / totalMax));
else
System.out.println("There have been no paintings bought within the past year.");
System.out.println("\n\n Press <ENTER> to return to main menu...");
UserInterface.pressEnter ();
} // printReport
} // class PurchasesReport
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -