DEV Community

AmalaReegan
AmalaReegan

Posted on

3

Day 11 --> Today 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 #

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 +" "+ catches);
}
public void allrounder()
{
    System.out.println(player_name+" "+ score+" "+catches+" "+balls);
}
}

Enter fullscreen mode Exit fullscreen mode

Image description

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more