Guest User

Untitled

a guest
Jun 19th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Superhero {
  4.  
  5.  
  6.  
  7. // instance variables go below here
  8. private static int numberofHeroes;
  9. private static String heroname;
  10. private String secretID;
  11. private int numberofLifeChances;
  12. private int numberofPeopleSaved;
  13.  
  14. // the two constructors go below here
  15. public Superhero(String initheroname, String initsecretID, int initPeopleSaved) {
  16. numberofHeroes++;
  17. numberofLifeChances = 2;
  18. heroname = initheroname;
  19. secretID = initsecretID;
  20. numberofPeopleSaved = initPeopleSaved;
  21. }
  22.  
  23. public Superhero(String string) {
  24. // TODO Auto-generated constructor stub
  25. }
  26.  
  27. // getNumberOfHeroes() goes below here
  28. public static int getNumberOfHeroes() {
  29. return numberofHeroes;
  30. }
  31.  
  32. // recordSave() goes below here
  33. public void recordSave() {
  34. numberofPeopleSaved++;
  35. }
  36. // the second recordSave method goes here
  37. public void recordSave(int num) {
  38. numberofPeopleSaved += num;
  39. }
  40.  
  41. // killHero() goes below here
  42. public void killHero() {
  43. if (numberofLifeChances > 0) {
  44. numberofLifeChances--; }
  45. else {
  46. }
  47. // printSuperHeroRecord() goes below here
  48. System.out.println("The Hero is dead.");
  49. }
  50. public void printSuperHeroRecord() {
  51. System.out.println("Name: " + heroname);
  52. System.out.println("Secret Identity: " + secretID);
  53. System.out.print("Status: ");
  54. if (numberofLifeChances > 0 ) {
  55. System.out.println("Alive"); }
  56. else {
  57. System.out.println("Dead");
  58. }
  59. System.out.println("Number of People Saved: " + numberofPeopleSaved);
  60. }
  61.  
  62. public static void main(String[] args)
  63.  
  64. {
  65. Scanner in = new Scanner(System.in);
  66.  
  67. // Create a superhero called Spider-Man
  68.  
  69. System.out.println("Creating Spider-Man.......");
  70. Superhero spiderman = new Superhero("Spider-Man");
  71.  
  72. // Ask the user to enter a superhero name
  73. System.out.println("\nWhat is the name of your superhero?");
  74. String heroname = in.nextLine();
  75.  
  76. System.out.println("What is his secret identity?");
  77. String secretID = in.nextLine();
  78.  
  79. System.out.println("Creating your super hero.......");
  80.  
  81. Superhero yourhero = new Superhero(heroname);
  82.  
  83. System.out.println(heroname + " just saved 10 lives!" );
  84. yourhero.recordSave(10);
  85. System.out.println("\nSpiderman just saved 100 lives!" );
  86. spiderman.recordSave(100);
  87.  
  88.  
  89. System.out.println("Oops, Spider-Man was shot dead twice!");
  90. spiderman.killHero();
  91. spiderman.killHero();
  92.  
  93.  
  94. System.out.print("\nYour hero saved a kidnapped kid ");
  95. System.out.println("but was shot once");
  96. yourhero.killHero();
  97. yourhero.recordSave();
  98.  
  99. System.out.println("\n---- Superhero information ----");
  100. int numberofHeroes = Superhero.getNumberOfHeroes();
  101. System.out.println("There are " + numberofHeroes + " known superheroes.");
  102. spiderman.printSuperHeroRecord();
  103. System.out.println("\nThere are " + numberofHeroes + "known Superheroes.");
  104.  
  105. spiderman.printSuperHeroRecord();
  106. yourhero.printSuperHeroRecord();
  107.  
  108. }
  109. }
Add Comment
Please, Sign In to add comment