Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Instructions
- * Solve the problem with Java Code
- * Submit only the .java or .text file
- * Read the questions and write java code accordingly
- Read the following question and write shortcode for the questions:
- Read the following user-story and wite java code. Write Cricketer and Main class in
- different package and import Cricketer class in the Main class.
- Suppose, you have been given a task to develop a program that will
- manage the activity of a cricketer. A Cricketer has some property
- like name, age, country, number of runs, number of wickets, and numbers of matches.
- You have to write three methods named increaseRun, increaseWicket and increaseMatch
- those methods will increase run, wicket and match of cricketer. Each method will take
- a single parameter for run, wicket, and match respectively. Write another method named
- printInfo that will print all the information of that cricketer. Write another class
- named Controller. In the Controller class create an object of cricketer class and
- initialize the object. Take input from user for run, wicket and match and call all
- three methods. Finally call the printInfo method to print the details information.//
- package com.company.cricketer;
- import java.util.Scanner;
- public class Cricketer {
- Scanner input = new Scanner(System.in);
- String name;
- String country;
- int age;
- int numberOfRuns;
- int numberOfWickets = 0;
- int numberOfMatches;
- public void getInput(){
- System.out.println("Enter Player Name : ");
- name = input.nextLine();
- System.out.println("Enter Player's Country Name : ");
- country = input.nextLine();
- System.out.println("Enter Player's Age : ");
- age = input.nextInt();
- }
- public void increaseRun(int run){
- numberOfRuns = numberOfRuns + run;
- }
- public void increaseWicket(int wicket){
- numberOfWickets = numberOfWickets + wicket;
- }
- public void increaseMatch(int match){
- numberOfMatches = numberOfMatches + match;
- }
- public void printInfo(){
- System.out.println();
- System.out.println("Name : " + name);
- System.out.println("Country : " + country);
- System.out.println("Age : " + age);
- System.out.println("Number of Matches : " + numberOfMatches);
- System.out.println("Number of Wickets : " + numberOfWickets);
- System.out.println("Total Runs : " + numberOfRuns);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement