Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Zachary Golden
- *November 16,2010
- *Earthquake.java
- *describes the effects of an earthquake
- */
- public class Earthquake
- {
- /**
- * Constructs an Earthquake object.
- * @param magnitude the magnitude on the Richter scale
- */
- public Earthquake(double magnitude)
- {
- richter = (int) magnitude;
- }
- /**
- * Gets a description of the effect of the earthquake.
- * @return the description of the effect
- */
- public String getDescription()
- {
- String r;
- switch(richter)
- {
- case 6: System.out.print("Most structures fall"); break;
- case 5: System.out.print("Many buildings destroyed"); break;
- case 4: System.out.print("Many buildings considerably damaged, some collapse"); break;
- case 3: System.out.print("Damage to poorly constructed buildings"); break;
- case 2: System.out.print("Felt by many people, no destruction"); break;
- case 1: System.out.print("Generally not felt by people"); break;
- default r: "Numbers are invalid"; break;
- }
- }
- private static int richter;
- }
- /*
- * Zachary Golden
- * November 16, 2010
- * EarthquakeRunner.java
- *
- */
- import java.util.Scanner;
- public class EarthquakeRunner
- {
- Scanner in = new Scanner(System.in);
- System.out.print("Enter a magnitude on the Richter scale: ");
- double magnitude = in.nextDouble();
- Earthquake quake = new Earthquake(magnitude);
- System.out.println(quake.getDescription);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement