java coding problem

Asked 2 years ago, Updated 2 years ago, 22 views

I'm a beginner at Java.

Write the Baseball Player class, Battery class, and Pitcher class that meet the following conditions.

Conditions 1) The Baseball Player class, which represents a baseball player, has the player name palyer name, stamina, and salary sdlarry Have as an instance variable. 2) The Batter class representing the batter inherits the Baseball Player class, and the variable of the upper class has a contact variable representing hitting ability. 3) The Pitcher class, which represents the pitcher, also inherits the Baseball Player class, and there is a ballSpeed variable that represents the highest speed of the ball in addition to the variable of the upper class. 4) The three classes have a constructor that receives all variables and initializes them. 5) When the training method of the Baseball Player class is executed, the player's physical strength is increased by 1, additionally, the batter can increase the batting ability by 2, and the pitcher can increase the maximum speed of the ball by 1. However, implement the training method by overriding it.

My friend showed me the question and my hair... I don't know how to code.

java

2022-09-20 21:38

1 Answers

class BaseballPlayer {
    string palyerName;
    int stamina;
    int sdlary;
    BaseballPlayer(string palyerName,int stamina,int sdlary){
        this.palyerName = palyerName;
        this.stamina = stamina;
        this.sdlary = sdlary;
    }
    void training(){
        stamina = stamina + 1;
    }
}

class Batter extends BaseballPlayer {
    Batter (string palyerName,int stamina,int sdlary,int contact){
        this.palyerName = palyerName;
        this.stamina = stamina;
        this.sdlary = sdlary;
        this.contact = contact;
    }
    int contact;
    void training(){
        super.training();
        contact = contact + 2;
    }
}

class Pitcher extends BaseballPlayer {
    int ballSpeed;
    void training(){
        super.training();
        ballSpeed = ballSpeed + 1;
    }
    Pitcher(string palyerName,int stamina,int sdlary,int ballSpeed){
        this.palyerName = palyerName;
        this.stamina = stamina;
        this.sdlary = sdlary;
        this.ballSpeed = ballSpeed;
    }
}

You can do it like this. I did not deliberate on the review.

Please review and submit it properly, and don't ask questions to replace the assignment from now on.

Thank you.


2022-09-20 21:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.