-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"files.exclude": { | ||
"**/.class": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
public class Battery { | ||
private double capacity; | ||
private double remaining; | ||
|
||
public Battery(double capacity) { | ||
this.capacity = capacity; | ||
this.remaining = capacity; | ||
} | ||
|
||
public void drain(double amount) { | ||
remaining -= amount; | ||
} | ||
|
||
public void charge() { | ||
remaining = capacity; | ||
} | ||
|
||
public double getRemaining() { | ||
return remaining; | ||
} | ||
|
||
public static void main(String... args) { | ||
Battery battery = new Battery(100); | ||
battery.drain(60); | ||
System.out.println("Battery remaining: " + battery.getRemaining()); | ||
battery.charge(); | ||
System.out.println("Battery remaining after charge: " + battery.getRemaining()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
public class MarvelCharacter { | ||
private String name, power; | ||
private int comicsAppeared; | ||
|
||
public MarvelCharacter() { | ||
name = ""; | ||
power = ""; | ||
comicsAppeared = 0; | ||
} | ||
|
||
public MarvelCharacter(String name, String power, int comicsAppeared) { | ||
this.name = name; | ||
this.power = power; | ||
this.comicsAppeared = comicsAppeared; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getPower() { | ||
return power; | ||
} | ||
|
||
public int getComicsAppeared() { | ||
return comicsAppeared; | ||
} | ||
|
||
public void addPower(String newPower) { | ||
power += ", " + newPower; | ||
} | ||
|
||
public void setComicsAppeared(int comicsAppeared) { | ||
this.comicsAppeared = comicsAppeared; | ||
} | ||
|
||
public int randComic() { | ||
return (int) (Math.random() * comicsAppeared) + 1; | ||
} | ||
|
||
public static void main(String[] args) { | ||
MarvelCharacter avenger1 = new MarvelCharacter(); | ||
MarvelCharacter spiderMan = new MarvelCharacter("Spider-Man", "webbing projection", 300); | ||
MarvelCharacter symbiote = new MarvelCharacter("Venom", "shapeshifting", 144); | ||
System.out.println(symbiote.getName()); | ||
symbiote.addPower(spiderMan.getPower()); | ||
spiderMan.setComicsAppeared(spiderMan.getComicsAppeared() + 1); | ||
int symbioteComic = symbiote.randComic(); | ||
System.out.println(symbioteComic); | ||
|
||
MarvelCharacter blueBatman = new MarvelCharacter("Blue Batman", "Laser Vision", 5); | ||
System.out.println("Marvel Character Name: " + blueBatman.name); | ||
System.out.println("Marvel Character Power: " + blueBatman.power); | ||
System.out.println("Marvel Character Comics Appeared: " + blueBatman.comicsAppeared); | ||
blueBatman.addPower("Hearing"); | ||
blueBatman.setComicsAppeared(blueBatman.getComicsAppeared() + 2); | ||
System.out.println("Marvel Character Name: " + blueBatman.name); | ||
System.out.println("Marvel Character Power: " + blueBatman.power); | ||
System.out.println("Marvel Character Comics Appeared: " + blueBatman.comicsAppeared); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
public class Person { | ||
private String name; | ||
private String friendList; | ||
|
||
public Person(String name) { | ||
this.name = name; | ||
this.friendList = name; | ||
} | ||
|
||
public String getFriends() { | ||
return friendList; | ||
} | ||
|
||
public void befriend(Person p) { | ||
friendList += ", " + p.name; | ||
} | ||
|
||
public void unfriend(Person p) { | ||
friendList = friendList.replace(", " + p.name, ""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import java.util.Random; | ||
|
||
public class Pokemon { | ||
private String name; | ||
private int hp; | ||
private String bestAttack; | ||
|
||
public Pokemon() { | ||
name = ""; | ||
hp = 0; | ||
} | ||
|
||
public Pokemon(String name, String bestAttack, int hp) { | ||
this.name = name; | ||
this.hp = hp; | ||
this.bestAttack = bestAttack; | ||
} | ||
|
||
public double getHitPoints() { | ||
return hp; | ||
} | ||
|
||
public void battle() { | ||
int damage = new Random().nextInt(31) + 20; | ||
hp -= damage; | ||
System.out.println(name + " got hit for " + damage + " hitpoints!"); | ||
} | ||
|
||
public boolean knockedOut() { | ||
return hp <= 0; | ||
} | ||
|
||
public static void main(String[] args) { | ||
Pokemon charmander = new Pokemon("Charmander", "Blaze", 39); | ||
|
||
System.out.println("Charmander has " + charmander.getHitPoints() + " hitpoints."); | ||
charmander.battle(); | ||
System.out.println("Charmander has " + charmander.getHitPoints() + " hitpoints."); | ||
System.out.println("Charmander is knocked out: " + charmander.knockedOut()); | ||
charmander.battle(); | ||
System.out.println("Charmander is knocked out: " + charmander.knockedOut()); | ||
|
||
Pokemon abra = new Pokemon(); | ||
abra.getHitPoints(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
public class RoachPopulation { | ||
private int population; | ||
|
||
public RoachPopulation(int initialPopulation) { | ||
population = initialPopulation; | ||
} | ||
|
||
public void breed() { | ||
population *= 2; | ||
} | ||
|
||
public void spray(double percent) { | ||
population -= (int) (population * percent / 100); | ||
} | ||
|
||
public int getRoaches() { | ||
return population; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
public class RoachSimulation { | ||
RoachPopulation pop; | ||
|
||
public static void main(String[] args) { | ||
RoachPopulation pop = new RoachPopulation(10); | ||
pop.breed(); | ||
pop.spray(10); | ||
System.out.println("Roaches: " + pop.getRoaches()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters