Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. /*Zachary Golden
  2.  *November 16,2010
  3.  *Earthquake.java
  4.  *describes the effects of an earthquake
  5.  */
  6.  
  7. public class Earthquake
  8. {
  9.     /**
  10.      * Constructs an Earthquake object.
  11.      * @param magnitude the magnitude on the Richter scale
  12.      */
  13.     public Earthquake(double magnitude)
  14.     {
  15.         richter = (int) magnitude;
  16.     }
  17.     /**
  18.      * Gets a description of the effect of the earthquake.
  19.      * @return the description of the effect
  20.      */
  21.     public String getDescription()
  22.     {
  23.         String r;
  24.         switch(richter)
  25.         {
  26.             case 6: System.out.print("Most structures fall"); break;
  27.             case 5: System.out.print("Many buildings destroyed"); break;
  28.             case 4: System.out.print("Many buildings considerably damaged, some collapse"); break;
  29.             case 3: System.out.print("Damage to poorly constructed buildings"); break;
  30.             case 2: System.out.print("Felt by many people, no destruction"); break;
  31.             case 1: System.out.print("Generally not felt by people"); break;
  32.             default r: "Numbers are invalid"; break;
  33.         }
  34.     }
  35.     private static int richter;
  36. }
  37.  
  38.  
  39. /*
  40.  * Zachary Golden
  41.  * November 16, 2010
  42.  * EarthquakeRunner.java
  43.  *
  44.  */
  45.  
  46. import java.util.Scanner;
  47.  
  48. public class EarthquakeRunner
  49. {
  50.     Scanner in = new Scanner(System.in);
  51.    
  52.     System.out.print("Enter a magnitude on the Richter scale: ");
  53.     double magnitude = in.nextDouble();
  54.     Earthquake quake = new Earthquake(magnitude);
  55.     System.out.println(quake.getDescription);
  56.    
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement