DEV Community

Pavitra Aravind
Pavitra Aravind

Posted on

2 1

Today Task

Task:

  1. Create a class Called PlayGround
  2. Create non-static variables as below. int score, balls, catches; String player_name;
  3. Create main method.
  4. Inside main method, create two instances as below. PlayGround player1 = new PlayGround("dhoni", 100, 3); PlayGround player2 = new PlayGround("jadeja", 56, 2, 30);
  5. Create appropriate constructors for handling above objects.
  6. Using player1 object, call batting() method. Print - score, player_name.
  7. Using player2 object, call allrounder() method. Print - score, player_name, balls, catches

Input:

class PlayGround
{

int score, balls, catches;
String player_name;

public PlayGround(String player_name, int score, int catches)
{
this.player_name = player_name;
this.score = score;
this.catches=catches;
}

public PlayGround(String player_name, int score, int catches, int balls)
{
this.player_name = player_name;
this.score = score;
this.catches = catches;
this.balls = balls;
}

public static void main(String[] args)
{
PlayGround player1 = new PlayGround("dhoni",100,3);
PlayGround player2 = new PlayGround("jadeja",56,2,30);

player1.batting();
player2.allrounder();

}

public void batting()
{
System.out.println(player_name + " "+ score);
}

public void allrounder()
{
System.out.println(player_name + " "+ score + " " + balls + " "+ catches + " ");
}
}

Output:

Image description

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay