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

📄 photo.java

📁 Java经典例程 从外国一大学计算机教授出版物下载的代码 经典
💻 JAVA
字号:
import java.io.*;
import javagently.*;
import myutilities.*;
import java.util.*;

class Photo {

  /* The class photo program   by J M Bishop  January 1997
   * =======================   revised January 1998
   *                           revised for JFC August 2000
   *
   * Uses linked lists to set up the rows
   * for a class photo, based on height.
   *
   * Illustrates List handling.
   */

  LinkedList studentList = new LinkedList();

  public static void main (String args []) throws IOException{
    new Photo();
  }

  Photo () throws IOException {
    System.out.println("**** The class Photo ****");
    lineUp();
    for (int row = 1; studentList.size() > 0; row++)
      pickOff (row);
  }

  void lineUp () throws IOException {

    Stream in = new Stream ("students.dat", Stream.READ);
    System.out.println("The students as read in are:");
    while (true) {
      try {
        double h = in.readDouble();
        String n = in.readString();
        Student s = new Student (h, n);
        System.out.println(s);

        // Find the place for the new entry
        int before = 0;
        for (ListIterator e = studentList.listIterator(); e.hasNext();) {
          if (s.compareTo(e.next()) > 0)
            break;
          before++;
	    }

        // add the new entry
        studentList.add(before,s);
      }
      catch (EOFException e) {break;}
   }
   System.out.println("The students in height order are:");

   for (ListIterator e = studentList.listIterator(); e.hasNext();)
     System.out.println(e.next());
  }

  void pickOff (int row) {
    System.out.println("Row "+row+"\t");
    LinkedList line = new LinkedList ();
    Student s;
    s = (Student) studentList.removeFirst();
    line.addLast(s);
    for (int i = 0; i<rowSize/2; i++) {
      s = (Student) studentList.removeFirst();
      line.addLast(s);
      s = (Student) studentList.removeFirst();
      line.addFirst(s);
    }
    for (ListIterator e = line.listIterator(); e.hasNext();)
      System.out.println(e.next());
  }

  static final int rowSize = 7;
}

⌨️ 快捷键说明

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