Exp 7
Exp 7
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);
}
}
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