Sorry, I know that this code can be shortened significantly here and there, I just haven't really gotten how inheritance really works.
My question is, how do I make it so that the methods within my machoke and machop class don't print out those redundant stats.
public class FP {
public void string() {
System.out.println("A Standard fighting pokemon's stats are:");
}
public double weight() {
double fWeight = 65;
System.out.println("Weight: " + fWeight);
return fWeight;
}
public double arm() {
double fArm = 21;
System.out.println("Arm Reach: " + fArm);
return fArm;
}
public double leg() {
double fLeg = 22;
System.out.println("Leg Reach: " +fLeg);
return fLeg;
}
public double punch() {
double fPunch = 40;
System.out.println("Punch Damage: " + fPunch);
return fPunch;
}
public double kick() {
double fKick = 35;
System.out.println("Kick Damage: " + fKick);
return fKick;
}
public double bodySlam() {
double fBodySlam = 150;
System.out.println("Body Slam damage: " + fBodySlam);
return fBodySlam;
}
}
public class Machop extends FP {
public double DMG_MULTI = 1.5;
public void string() {
System.out.println("Machop's stats are:");
}
public double bodySlam(){
double fBodySlam = super.bodySlam()*DMG_MULTI;
System.out.println("Body Slam damage: "+fBodySlam);
System.out.println();
return fBodySlam;
}
}
public class Machoke extends Machop {
public void string() {
System.out.println("Machoke's stats are:");
}
public double weight() {
double fWeight = super.weight()*1.75;
System.out.println("Weight: " + fWeight);
return 0;
}
public double arm() {
double fArm = super.arm()*1.75;
System.out.println("Arm Reach: " + fArm);
return fArm;
}
public double leg() {
double fLeg = super.leg()*1.75;
System.out.println("Leg Reach: " +fLeg);
return fLeg;
}
public double punch() {
double fPunch = super.punch()*1.75;
System.out.println("Punch Damage: " + fPunch);
return fPunch;
}
public double kick() {
double fKick = super.kick()*1.75;
System.out.println("Kick Damage: " + fKick);
return fKick;
}
public double bodySlam() {
double fBodySlam = super.bodySlam()*2;
System.out.println("Body Slam damage: " + fBodySlam);
return fBodySlam;
}
public double submission(){
double fSubmission = super.bodySlam()*1.5;
System.out.println("Submission damage: " + fSubmission);
System.out.println();
return 0;
}
}
public class Call {
public static void main(String args[]) {
FP fp = new FP();
fp.string();
fp.weight();
fp.arm();
fp.leg();
fp.punch();
fp.kick();
fp.bodySlam();
System.out.println();
Machop a = new Machop();
a.string();
a.weight();
a.arm();
a.leg();
a.punch();
a.kick();
a.bodySlam();
Machoke b = new Machoke();
b.string();
b.weight();
b.arm();
b.leg();
b.punch();
b.kick();
b.bodySlam();
b.submission();
}
}
Output:
A Standard fighting pokemon's stats are:
Weight: 65.0
Arm Reach: 21.0
Leg Reach: 22.0
Punch Damage: 40.0
Kick Damage: 35.0
Body Slam damage: 150.0Machop's stats are:
Weight: 65.0
Arm Reach: 21.0
Leg Reach: 22.0
Punch Damage: 40.0
Kick Damage: 35.0
Body Slam damage: 150.0
Body Slam damage: 225.0Machoke's stats are:
Weight: 65.0
Weight: 113.75
Arm Reach: 21.0
Arm Reach: 36.75
Leg Reach: 22.0
Leg Reach: 38.5
Punch Damage: 40.0
Punch Damage: 70.0
Kick Damage: 35.0
Kick Damage: 61.25
Body Slam damage: 150.0
Body Slam damage: 225.0
Body Slam damage: 450.0
Body Slam damage: 150.0
Body Slam damage: 225.0
Submission damage: 337.5