A teen ager Sport Club offers many sports to the registered members write a java code to keep facilitate the players.
Create a class name Play
⦁ Create the following method name
⦁ checkMatchSchedule(): This method will display the match schedule.
⦁ checkMatchSchedule():(): This method will display the match practice schedule.
⦁ rules(): display the sport rule.
Create the following classes:
⦁ Tennis, Cricket and football.
⦁ These classes will inherit the play class and override the parent methods.
Create a Player class:
⦁ playerId, name , height, weight, age.
⦁ checkMatchSch(): This method will take input from user inquiring which sport match schedule would he like to view and display the schedule of the respective Sport.
⦁ checkRules():This method will take input from user inquiring which sport rules would he like to view and display the rule of the respective Sport.
Create a Main class and test the methods.
class Play {
/**
* checkMatchSchedule(): This method will display the match schedule.
*/
public void checkMatchSchedule() {
System.out.println("The match schedule:");
}
/**
* checkPracticeSchedule():(): This method will display the match practice schedule.
*/
public void checkPracticeSchedule() {
System.out.println("The match practice schedule:");
}
/**
* rules(): display the sport rule.
*/
public void rules() {
System.out.println("The sport rule:");
}
}
class Tennis extends Play {
/**
* checkMatchSchedule(): This method will display the match schedule.
*/
@Override
public void checkMatchSchedule() {
super.checkMatchSchedule();
System.out.println("Apr 26-May 3");
System.out.println("BMW Open by FWU");
System.out.println("Munich, Germany\n");
System.out.println("Apr 26-May 3");
System.out.println("Millennium Estoril Open");
System.out.println("Estoril, Portugal");
}
/**
* checkPracticeSchedule():(): This method will display the match practice schedule.
*/
@Override
public void checkPracticeSchedule() {
super.checkPracticeSchedule();
System.out.println("Apr 20-May 23");
System.out.println("Practice");
System.out.println("Apr 24-Apr 25");
System.out.println("Team camp");
}
/**
* rules(): display the sport rule.
*/
@Override
public void rules() {
super.rules();
String ruleStr= "Cricket is played by two teams of 11, with one side taking a turn to bat a ball and score runs,\n"
+ "while the other team will bowl and field the ball to restrict the opposition from scoring.\n"
+ "The main objective in cricket is to score as many runs as possible against the opponent.\n"
+ "Before the match begins, the captain of both teams will toss a coin, with the winner of\n"
+ "the toss being able to decide which team bats and fields first.\n";
System.out.println(ruleStr);
}
}
class Cricket extends Play {
/**
* checkMatchSchedule(): This method will display the match schedule.
*/
@Override
public void checkMatchSchedule() {
super.checkMatchSchedule();
System.out.println("May 26-May 3");
System.out.println("BMW Open by FWU");
System.out.println("Munich, Germany\n");
System.out.println("May 26-May 3");
System.out.println("Millennium Estoril Open");
System.out.println("Estoril, Portugal");
}
/**
* checkPracticeSchedule():(): This method will display the match practice schedule.
*/
@Override
public void checkPracticeSchedule() {
super.checkPracticeSchedule();
System.out.println("May 20-May 23");
System.out.println("Practice");
System.out.println("May 24-Apr 25");
System.out.println("Team camp");
}
/**
* rules(): display the sport rule.
*/
@Override
public void rules() {
super.rules();
String ruleStr= "A ball must land within bounds for play to continue; if a player hits the ball outside of bounds, this results in the loss of the point for them.\n";
ruleStr+= "Players/teams cannot touch the net or posts or cross onto the opponent’s side.\n";
ruleStr+= "Players/teams cannot carry the ball or catch it with the racquet.\n";
ruleStr+= "Players cannot hit the ball twice.\n";
ruleStr+= "Players must wait until the ball passes the net before they can return it.\n";
ruleStr+= "A player that does not return a live ball before it bounces twice loses the point.\n";
ruleStr+= "If the ball hits or touches the players, that counts as a penalty.\n";
ruleStr+= "If the racquet leaves the hand or verbal abuse occurs, a penalty is given.\n";
ruleStr+= "Any ball that bounces on the lines of boundary are considered good.\n";
ruleStr+= "A serve must bounce first before the receiving player can return it.\n";
System.out.println(ruleStr);
}
}
class Football extends Play {
/**
* checkMatchSchedule(): This method will display the match schedule.
*/
@Override
public void checkMatchSchedule() {
super.checkMatchSchedule();
System.out.println("June 26-May 3");
System.out.println("BMW Open by FWU");
System.out.println("Munich, Germany\n");
System.out.println("June 26-May 3");
System.out.println("Millennium Estoril Open");
System.out.println("Estoril, Portugal");
}
/**
* checkPracticeSchedule():(): This method will display the match practice schedule.
*/
@Override
public void checkPracticeSchedule() {
super.checkPracticeSchedule();
System.out.println("June 20-May 23");
System.out.println("Practice");
System.out.println("June 24-Apr 25");
System.out.println("Team camp");
}
/**
* rules(): display the sport rule.
*/
@Override
public void rules() {
super.rules();
String ruleStr= "A match consists of two 45 minutes halves with a 15 minute rest period in between.\r\n" +
"Each team can have a minimum off 11 players (including 1 goalkeeper who is the only player allowed to handle the ball within the 18 yard box) and a minimum of 7 players are needed to constitute a match.\r\n" +
"The field must be made of either artificial or natural grass. The size of pitches is allowed to vary but must be within 100-130 yards long and 50-100 yards wide. The pitch must also be marked with a rectangular shape around the outside showing out of bounds, two six yard boxes, two 18 yard boxes and a centre circle. A spot for a penalty placed 12 yards out of both goals and centre circle must also be visible.\r\n" +
"The ball must have a circumference of 58-61cm and be of a circular shape.\n";
System.out.println(ruleStr);
}
}
class Player {
// playerId, name , height, weight, age.
private int playerId;
private String name;
private int height;
private double weight;
private int age;
public Player() {
}
public Player(int playerId, String name, int height, double weight, int age) {
this.playerId = playerId;
this.name = name;
this.height = height;
this.weight = weight;
this.age = age;
}
/**
* @return the playerId
*/
public int getPlayerId() {
return playerId;
}
/**
* @param playerId the playerId to set
*/
public void setPlayerId(int playerId) {
this.playerId = playerId;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the height
*/
public int getHeight() {
return height;
}
/**
* @param height the height to set
*/
public void setHeight(int height) {
this.height = height;
}
/**
* @return the weight
*/
public double getWeight() {
return weight;
}
/**
* @param weight the weight to set
*/
public void setWeight(double weight) {
this.weight = weight;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
/**
* checkMatchSch(): This method will take input from user inquiring which sport
* match schedule would he like to view and display the schedule of the
* respective Sport.
*/
public void checkMatchSch(Play selectedSport) {
selectedSport.checkMatchSchedule();
}
public void checkPracticeSchedule(Play selectedSport) {
selectedSport.checkPracticeSchedule();
}
/**checkRules():This method will take input from user inquiring which sport
* rules would he like to view and display the rule of the respective Sport.
* @param selectedSport
*/
public void checkRules(Play selectedSport) {
selectedSport.rules();
}
}
public class Q186652 {
/**
* Main method
*
* @param args
*/
public static void main(String[] args) {
Player playerMikeSmith = new Player(1,"Mike Smith",185, 84.5, 23);
System.out.println("Player info");
System.out.println("Player Id: "+playerMikeSmith.getPlayerId());
System.out.println("Player name: "+playerMikeSmith.getName());
System.out.println("Player height: "+playerMikeSmith.getHeight());
System.out.println("Player weight: "+playerMikeSmith.getWeight());
System.out.println("Player age: "+playerMikeSmith.getAge()+"\n");
Tennis tennis=new Tennis();
playerMikeSmith.checkRules(tennis);
System.out.print("");
playerMikeSmith.checkMatchSch(tennis);
System.out.print("");
playerMikeSmith.checkPracticeSchedule(tennis);
Player playerMaryClark = new Player(1,"Mary Clark",175, 75, 21);
System.out.println("Player info");
System.out.println("Player Id: "+playerMaryClark.getPlayerId());
System.out.println("Player name: "+playerMaryClark.getName());
System.out.println("Player height: "+playerMaryClark.getHeight());
System.out.println("Player weight: "+playerMaryClark.getWeight());
System.out.println("Player age: "+playerMaryClark.getAge()+"\n");
Cricket cricket=new Cricket();
playerMaryClark.checkRules(cricket);
System.out.print("");
playerMaryClark.checkMatchSch(cricket);
System.out.print("");
playerMaryClark.checkPracticeSchedule(cricket);
Player playerPeterJohnson = new Player(1,"Peter Johnson",170, 70, 19);
System.out.println("Player info");
System.out.println("Player Id: "+playerPeterJohnson.getPlayerId());
System.out.println("Player name: "+playerPeterJohnson.getName());
System.out.println("Player height: "+playerPeterJohnson.getHeight());
System.out.println("Player weight: "+playerPeterJohnson.getWeight());
System.out.println("Player age: "+playerPeterJohnson.getAge()+"\n");
Football football=new Football();
playerPeterJohnson.checkRules(football);
System.out.print("");
playerPeterJohnson.checkMatchSch(football);
System.out.print("");
playerPeterJohnson.checkPracticeSchedule(football);
}
}
Comments
Leave a comment