0% found this document useful (0 votes)
8 views4 pages

Exp 7

The document outlines a Java programming assignment for creating a player class with subclasses for Cricket, Football, and Hockey players. It includes the code for the classes and methods to input and display player data. The program allows users to enter player details based on the sport selected and outputs the relevant information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Exp 7

The document outlines a Java programming assignment for creating a player class with subclasses for Cricket, Football, and Hockey players. It includes the code for the classes and methods to input and display player data. The program allows users to enter player details based on the sport selected and outputs the relevant information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SCTR’s PUNE INSTITUTE OF COMPUTER TECHNOLOGY PUNE - 411043

Department of Electronics & Telecommunication Engineering (E&TCE)


ASSESMENT YEAR: 2024-2025 CLASS: TE - 7 BATCH:- N7
SUBJECT: Fundamental of JAVA Programming
Assignment No: 7 Roll No: 32360 PERFORMANCE DATE:
SUBMISSION DATE:

Programmer Name: Shantanu Rojatkar


Batch: N7

Problem Statement: Write a program in Java to create a player class. Inherit the classes
Cricket_player, Football_player and Hockey_player from Player class.

Note: copy code and program output for all case here

package experiments;
import java.util.Scanner;
class Player{
String name, gameName, address, type;
int age, noOfGamesPlayed;
Scanner sc = new Scanner(System.in);

void get_data() {
System.out.println("Enter the name of player: ");
name = sc.next();
System.out.println("Enter the age of player: ");
age = sc.nextInt();
System.out.println("Enter the game name: ");
gameName = sc.next();
System.out.println("Enter the address of the game: ");
address = sc.next();
System.out.println("Enter the type of game: ");
type = sc.next();
}
void display() {
System.out.println("Name: "+name);
System.out.println("Age: "+age);
System.out.println("Game name: "+gameName);
System.out.println("Adress: "+address);
System.out.println("Type: "+type);
}
}

class Cricket_player extends Player{


int runs, wickets;
void get_data() {
System.out.println("Cricket Player: ");
super.get_data();
System.out.println("Enter the no.of runs made: ");
runs = sc.nextInt();
System.out.println("Enter the no.of wickets: ");
wickets = sc.nextInt();
}
void display() {
// System.out.println("Cricket Player: ");
super.display();
1
FJP_LAB_2024-25: Program input output
System.out.println("Runs: "+runs);
System.out.println("Wickets: "+wickets);
}
}

class Football_player extends Player{


int goals;
void get_data() {
System.out.println("Football Player: ");
super.get_data();
System.out.println("Enter the no.of goals scored: ");
goals = sc.nextInt();
}
void display() {
// System.out.println("FootBall Player: ");
super.display();
System.out.println("Goals Scored: "+goals);
}
}

class Hockey_player extends Player{


int goals;
void get_data() {
System.out.println("Hockey Player: ");
super.get_data();
System.out.println("Enter the no.of goals scored: ");
goals = sc.nextInt();
}
void display() {
// System.out.println("Hockey Player:");
super.display();
System.out.println("Goals Scored: "+goals);
}
}

public class Exp7 {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
int op;
System.out.println("1-> Cricket \n2-> Football \n3-> Hockey \nEnter the sports
played by the player: ");
op = sc.nextInt();
switch(op) {
case 1:
Cricket_player ckp = new Cricket_player();
ckp.get_data();
System.out.println("\nDisplaying data: ");
ckp.display();
break;
case 2:
Football_player fbp = new Football_player();
fbp.get_data();
System.out.println("\nDisplaying data: ");
fbp.display();
break;
case 3:
Hockey_player hcp = new Hockey_player();
hcp.get_data();
System.out.println("\nDisplaying data: ");
2
FJP_LAB_2024-25: Program input output
hcp.display();
break;
default:
System.out.println("Error! Enter an appropriate input!");
}
sc.close();
}
}

Output:
1.
->Cricket
2-> Football
3-> Hockey
Enter thr sport played by the player:
1
Cricket player:
Enter the name of the player:Virat
Enter thr age of the player:
38
Enter thr game name:
World cup
Enter the address of the game:
India
Enter thr type of game:
International
Enter the no. of runs made:
223
Enter thr no. of wickets :
0

Displaying data:
Name:Virat
Age:38
Game name:Cricket
Address:India
Type:International
Runs:223
Wickets:0

2.
1->Cricket
2-> Football
3-> Hockey
Enter thr sport played by the player:
3
Hockey player:
Enter the name of the player:Harmanjeet
Enter thr age of the player:
24
Enter thr game name:
Olympics
Enter the address of the game:
Tokyo
Enter thr type of game:
International
Enter the no. of goals scored:
10

3
FJP_LAB_2024-25: Program input output
Displaying data:
Name:Harmanjeet
Age:24
Game name:Hockey
Address:Tokyo
Type:International
Goals:10

4
FJP_LAB_2024-25: Program input output

You might also like