java program To create a class called cricketer with data member’s cname and number of matches.
Create a derived class batsman and bowler from cricketer. Class batsman have data
member like total run and member function for initializing data member, calculating
average runs and displaying data. Class bowler has members, calculating average
wickets and display data
Answers
Answer:
ygfghkkygfg nugffdt the class of paper and the rest are colour graphics card and gift kardo and a second time in my life and work in your country the cricketers in the future of our games and activities which will try and get back in touch soon with more details about the HTML5 canvas art of living allahabad bank of india in my life and the other hand the wildcats the ok from the class is full of the day and time to get a chance please let the
Answer:
package com.company;
import java.util.Scanner;
class Cricketer {
public String cname;
public int nom;
public void setDataMain() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the name of Cricketer: ");
cname = sc.nextLine();
Scanner sc2 = new Scanner(System.in);
System.out.print("Enter the Number of matches of Cricketer: ");
nom = sc2.nextInt();
}
public void displayDataMain() {
System.out.println("Name " +cname);
System.out.println("Matches " +nom);
}
}
class Batsman extends Cricketer {
public int total_run;
public float average;
public void setData() {
Scanner sc4 = new Scanner(System.in);
System.out.print("\nEnter the Total Number of Runs: ");
total_run = sc4.nextInt();
}
public void displayData() {
System.out.println("Total Runs "+total_run);
}
}
class Bowler extends Cricketer {
public int wickets;
public float average;
public void setData() {
Scanner sc3 = new Scanner(System.in);
System.out.print("Enter the number of wickets: ");
wickets = sc3.nextInt();
}
public void displayData() {
System.out.println("Wickets "+wickets);
}
}
public class Main {
public static void main(String[] args) {
Bowler bowl = new Bowler();
Batsman bat = new Batsman();
Cricketer cal = new Cricketer();
cal.setDataMain();
bat.setData();
bowl.setData();
cal.displayDataMain();
bat.displayData();
bowl.displayData();
bowl.average = (float) bowl.wickets/cal.nom;
bat.average = (float) bat.total_run/cal.nom;
System.out.println("Batting Average: "+bat.average);
System.out.println("Bowling Average: "+bowl.average);
}
}