import java.awt.*; import java.awt.event.*; public class myWindow extends Frame implements ActionListener { public myWindow (String name, int size, int location) { setTitle(name); setSize(size, size); setLocation(location,location); setBackground(Color.white); setVisible(true); } public void paint(Graphics g) { g.drawLine(100,100,200,200); } public void actionPerformed(ActionEvent e) { } } public class StockProfit { // Determine best buy-sell period // Author: Max Kamin, June 24, 1997 public static void main (String[] args) { myWindow f = new myWindow("myWindow", 300, 10); // Open a graphics window int minPrice, // lowest price so far priceToday, // last price input profit = 0; // best profit possible so far // Determine initial minimum price System.out.print("Enter value of stock : "); priceToday = Keyboard.readInt(); minPrice = priceToday; // what is the next day's price? System.out.print("Enter value of stock : "); priceToday = Keyboard.readInt(); while (!Keyboard.eof()) { // Does a sell today maximize profit? if (priceToday - minPrice > profit) profit = priceToday - minPrice; // Is today a new minimum price? if (priceToday < minPrice) minPrice = priceToday; // Next day's price. System.out.print("Enter value of stock : "); priceToday = Keyboard.readInt(); } System.out.println("Maximum profit = " + profit + " dollars."); } }