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

📄 computefuturetrends.java

📁 该程序有17个java源文件。是经典奥斯波特艺术品商人软件工程例子
💻 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 + -