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

📄 fashionability.java

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

public class Fashionability
{

  protected	String	firstName;		// first name of artist
  protected String	lastName;		// last name of artist
  protected double	coefficient;	// fashionability coefficient

  // getters-setters for Fashionability
  public String getFirstName ()			{ return firstName; }
  public void   setFirstName (String n) { firstName = n; }
  public String getLastName ()			{ return lastName; }
  public void   setLastName (String n)	{ lastName = n; }
  public double  getCoefficient ()		{ return coefficient; }
  public void   setCoefficient (double c) { coefficient = c; }

  public void getDescription ()
  //
  //	 retrieves fashionability description information
  //
  {

	UserInterface.clearScreen ();

	//
	// request fashionability object information
	//

	System.out.println("Please enter the following information concerning the artist whose");
	System.out.println("fashionability coefficient you wish to change.");
	System.out.println("Note: - Use an underscore in place of any spaces.");
	System.out.println("      - Do not leave any request blank.\n\n");

	System.out.print("Enter the FIRST name of the artist: ");
	firstName = UserInterface.getString();

	System.out.print("Enter the LAST name of the artist: ");
	lastName = UserInterface.getString();

	System.out.print("Enter the new fashionability coefficient for this artist: ");
	coefficient = UserInterface.getDouble();

  } // getDescription

//	-------------------------------------------------------------------------------------------------------------------

  public void readFash (DataInputStream fileName) // stream object where fashionability information is read
  //
  //	 reads a fashionability object from fileName
  //     Note: Java serialization could be used as an alternative to this approach
  //
  throws IOException {
	  firstName = fileName.readUTF();
	  lastName = fileName.readUTF();
	  coefficient = fileName.readDouble();

  } // readFash

//	-------------------------------------------------------------------------------------------------------------------

  public void writeFash (DataOutputStream fileName)	// stream object where fashionability information is written
  //
  //	 writes a fashionability object to fileName
  //     Note: Java serialization could be used as an alternative to this approach
  //
  throws IOException {

	if(firstName.length() > 0)
	{
	  fileName.writeUTF(firstName);
	  fileName.writeUTF(lastName);
	  fileName.writeDouble(coefficient);
	}

  } // writeFash

//	-------------------------------------------------------------------------------------------------------------------

  public void addNewFash ()
  //
  //	 allows the user to add/update the fashionability coefficient
  //	 of an object of FashionabilityCoefficientClass
  //
  throws IOException {

    DataInputStream inTmp, inCopy;			// stream objects used for file input
	DataOutputStream outTmp, outCopy;		// stream objects used for file output
    boolean found = false;					// indicates if object insertion point found
	Fashionability tempFash;	        	// temporary object used for file copying
    File fashExists = new File("fash.dat"); // check if fash file exists

    //
    // obtain information about the new fashionability object
    //
    getDescription ();

  	  inTmp = new DataInputStream(new BufferedInputStream(new FileInputStream("fash.dat")));
	  outTmp = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("tempF.dat")));
      tempFash = new Fashionability();

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

        //
	    // read/write a temporary object from the fashionability file
	    //
	    tempFash.readFash (inTmp);
	    tempFash.writeFash (outTmp);

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

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

	  inCopy = new DataInputStream(new BufferedInputStream(new FileInputStream("tempF.dat")));
	  outCopy = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("fash.dat")));

	//
	// copy the temporary file to a new artist file
	// while inserting the new artist name in the proper location
	//
	while (inCopy.available() != 0)
	{

		//
		// read/write a temporary fashionability object from the temporary file
		//
		tempFash.readFash (inCopy);

		//
		// copy the temporary file to a new fashionability file
		// while updating/inserting the fashionability object
		//
		if ((UserInterface.compareStr (tempFash.lastName, lastName) < 0) || found)
		  tempFash.writeFash (outCopy);
		else
	      if ((UserInterface.compareStr (tempFash.lastName, lastName)  > 0))
		  {
		    writeFash (outCopy);
		    tempFash.writeFash (outCopy);
		    found = true;
		  }
		  else
	 	    if ((UserInterface.compareStr (tempFash.firstName, firstName) == 0))
		    {
			  tempFash.writeFash (outCopy);
			  found = true;
		    }
		    else
		      if ((UserInterface.compareStr (tempFash.firstName, firstName) < 0))
		        tempFash.writeFash (outCopy);
		      else
		      {
		      	writeFash (outCopy);
		        tempFash.writeFash (outCopy);
		        found = true;
		      }

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

	  inCopy.close ();

    //
    // write the fashionability object to the end of the fashionability file
    //
    if (!found)
 	  writeFash (outCopy);

    outCopy.close ();

  	System.out.println();
    System.out.println(" Press <ENTER> to return to main menu...");

    UserInterface.pressEnter ();

  } // addNewFash

} // class Fashionability

⌨️ 快捷键说明

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