forked from Jared-Adamson/CSE_Java_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuperHero.java
More file actions
88 lines (74 loc) · 2.23 KB
/
SuperHero.java
File metadata and controls
88 lines (74 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Author: Jared Adamson
// Title: Lab 6
// Define a public class SuperHero
//-->
public class SuperHero
{
private static int numberOfHeroes;
private String heroName;
private String secretIdentity;
private int numberOfLifeChances;
private int numberOfPeopleSaved;
public SuperHero(String hName, String sIden, int numSaved)
{
// increment the numberOfHeroes
numberOfHeroes++;
// assign 2 to numberOfLifeChances
numberOfLifeChances = 2;
// assign the input hName to variable heroName
heroName = hName;
// assign the input sIden to variable secretIdentity
secretIdentity = sIden;
// assign the input numSaved to variable numberOfPeopleSaved
numberOfPeopleSaved = numSaved;
}
// Pass a String variable hName as parameter
public SuperHero(String hName)
{
// increment the numberOfHeroes
numberOfHeroes++;
// assign 2 to numberOfLifeChances
numberOfLifeChances = 2;
// assign the input hName to variable heroName
heroName = hName;
// assign "unknown" to variable secretIdentity
secretIdentity = "unknown";
// initialize numberOfPeopleSaved to 0
numberOfPeopleSaved = 0;
}
// This method returns the numberOfHeroes
public static int getNumberOfHeroes()
{
return numberOfHeroes;
}
public void recordSave()
{
numberOfPeopleSaved++;
}
// Define a overloaded method recordSaved with integer num as input. Inside the method increment numberOfPeopleSaved by num
public void recordSave(int num)
{
numberOfPeopleSaved += num;
}
public void killHero()
{
// Write an if-else statement
if (numberOfLifeChances == 0)
System.out.println( heroName + " does not live any more!");
else
numberOfLifeChances--;
}
// define a public method with the name printSuperHeroRecord and return type void which prints the Super Hero record
//-->
public void printSuperHeroRecord()
{
System.out.println("\nSuperHero's name:\t"+ heroName);
System.out.println("Secret Identity:\t"+ secretIdentity);
System.out.print("Status:");
if(numberOfLifeChances ==0)
System.out.println("\tNot Alive");
else
System.out.println("\tAlive");
System.out.println("Num of Lives Saved:\t"+ numberOfPeopleSaved);
}
}