Browse Source

added files

master
Raphael Roberts 7 years ago
parent
commit
69fdea71fe
  1. BIN
      CS207-2-HW1.pdf
  2. 24
      TestWizard.java
  3. 31
      Wizard.java
  4. 27
      test.java
  5. BIN
      tracing.png

BIN
CS207-2-HW1.pdf

24
TestWizard.java

@ -0,0 +1,24 @@
public class TestWizard
{
public static void main( String[] args )
{
Wizard w1 = new Wizard();
w1.wizardDetails();
w1.drinkPotion();
w1.wizardDetails();
w1.drinkPotion( 25 );
w1.wizardDetails();
Wizard w2 = new Wizard( 90, "Wand", "Fire Bolt" );
w2.wizardDetails();
w2.drinkPotion();
w2.wizardDetails();
w2.drinkPotion( 5 );
w2.wizardDetails();
}
}

31
Wizard.java

@ -0,0 +1,31 @@
public class Wizard{
int health;
String weapon;
String spell;
public Wizard(){
this.health = 100;
this.weapon = "Staff";
this.spell = "Arcane Arrow";
}
public Wizard(int health,String weapon,String spell){
this.health = health;
this.weapon = weapon;
this.spell = spell;
}
public void drinkPotion(){
this.health += 10;
}
public void drinkPotion(int potion){
this.health += potion;
}
public void wizardDetails(){
System.out.println("This Wizard has a total health of: " + this.health);
System.out.println("This Wizard carries a " + this.weapon + " and can cast " + this.spell + ".");
System.out.println();
}
/*
public static void main(String[] args){
}
*/
}

27
test.java

@ -0,0 +1,27 @@
//test if assigning from existing to new class is by reference or by value
public class test{
public static void main(String[] args){
Example t1 = new Example(1);
Example t2 = new Example(3);
t2 = t1;
t1.printT();
t2.setT(2);
t1.printT();
t2.printT();
}
}
class Example{
int t;
public Example(int t){
this.t = t;
}
public void printT(){
System.out.println(this.t);
}
public void setT(int t){
this.t = t;
}
}

BIN
tracing.png

After

Width: 1152  |  Height: 648  |  Size: 40 KiB

Loading…
Cancel
Save