// CSE 142 Lecture 18 // PrintStreams, Objects // This program is a client of the Point object that we wrote // in class. It reads cities from a file, and draws them on // a DrawingPanel. It then asks the user for the epicenter and // radius of an earthquake and turns cities in the affected area red. import java.awt.*; import java.io.*; import java.util.*; public class PointMain { public static void main(String[] args) throws FileNotFoundException { // Get the city coordinates from the input file and // store them in an array of Point objects Scanner input = new Scanner(new File("cities.txt")); Point[] cities = new Point[input.nextInt()]; for (int i = 0; i < cities.length; i++) { cities[i] = new Point(input.nextInt(), input.nextInt()); } // Draw each city in the array on the panel DrawingPanel panel = new DrawingPanel(200, 200); Graphics g = panel.getGraphics(); for (int i = 0; i < cities.length; i++) { cities[i].draw(g); System.out.println(cities[i]); } // Get the epicenter and radius from the user Scanner console = new Scanner(System.in); System.out.print("Epicenter x? "); int epiX = console.nextInt(); System.out.print("Epicenter y? "); int epiY = console.nextInt(); System.out.print("Affected radius? "); int radius = console.nextInt(); // Draw a circle around affected cities, and turn those cities red Point epicenter = new Point(epiX, epiY); g.drawOval(epicenter.getX() - radius, epicenter.getY() - radius, radius * 2, radius * 2); g.setColor(Color.RED); for (int i = 0; i < cities.length; i++) { if (cities[i].distance(epicenter) < radius) { cities[i].draw(g); System.out.println(cities[i]); } } } }