Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Superhero {
- // instance variables go below here
- private static int numberofHeroes;
- private static String heroname;
- private String secretID;
- private int numberofLifeChances;
- private int numberofPeopleSaved;
- // the two constructors go below here
- public Superhero(String initheroname, String initsecretID, int initPeopleSaved) {
- numberofHeroes++;
- numberofLifeChances = 2;
- heroname = initheroname;
- secretID = initsecretID;
- numberofPeopleSaved = initPeopleSaved;
- }
- public Superhero(String string) {
- // TODO Auto-generated constructor stub
- }
- // getNumberOfHeroes() goes below here
- public static int getNumberOfHeroes() {
- return numberofHeroes;
- }
- // recordSave() goes below here
- public void recordSave() {
- numberofPeopleSaved++;
- }
- // the second recordSave method goes here
- public void recordSave(int num) {
- numberofPeopleSaved += num;
- }
- // killHero() goes below here
- public void killHero() {
- if (numberofLifeChances > 0) {
- numberofLifeChances--; }
- else {
- }
- // printSuperHeroRecord() goes below here
- System.out.println("The Hero is dead.");
- }
- public void printSuperHeroRecord() {
- System.out.println("Name: " + heroname);
- System.out.println("Secret Identity: " + secretID);
- System.out.print("Status: ");
- if (numberofLifeChances > 0 ) {
- System.out.println("Alive"); }
- else {
- System.out.println("Dead");
- }
- System.out.println("Number of People Saved: " + numberofPeopleSaved);
- }
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- // Create a superhero called Spider-Man
- System.out.println("Creating Spider-Man.......");
- Superhero spiderman = new Superhero("Spider-Man");
- // Ask the user to enter a superhero name
- System.out.println("\nWhat is the name of your superhero?");
- String heroname = in.nextLine();
- System.out.println("What is his secret identity?");
- String secretID = in.nextLine();
- System.out.println("Creating your super hero.......");
- Superhero yourhero = new Superhero(heroname);
- System.out.println(heroname + " just saved 10 lives!" );
- yourhero.recordSave(10);
- System.out.println("\nSpiderman just saved 100 lives!" );
- spiderman.recordSave(100);
- System.out.println("Oops, Spider-Man was shot dead twice!");
- spiderman.killHero();
- spiderman.killHero();
- System.out.print("\nYour hero saved a kidnapped kid ");
- System.out.println("but was shot once");
- yourhero.killHero();
- yourhero.recordSave();
- System.out.println("\n---- Superhero information ----");
- int numberofHeroes = Superhero.getNumberOfHeroes();
- System.out.println("There are " + numberofHeroes + " known superheroes.");
- spiderman.printSuperHeroRecord();
- System.out.println("\nThere are " + numberofHeroes + "known Superheroes.");
- spiderman.printSuperHeroRecord();
- yourhero.printSuperHeroRecord();
- }
- }
Add Comment
Please, Sign In to add comment