Suppose you have already written the class for a Bowler The

Suppose you have already written the class for a Bowler. The Bowler class has two fields, a full name and a high score. Write the main() method to create two instances of this Bowler class. Get the input from the user and send the name and high score values to the constructor method of the Bowler class.

Solution

Hi Buddy, please find the below java program

import java.util.*;

class Bowler{
String fullName;
int highScore;
//Constructor
Bowler(String fullName, int highScore){
this.fullName = fullName;
this.highScore = highScore;
}
//This method returns object as string
@Override
public String toString(){
return fullName+\" : \"+highScore;
}
}
class Main{
public static void main(String args[]){
//Initializing Scanner
Scanner obj = new Scanner(System.in);
System.out.println(\"Enter name and score of bowler 1\");
//Creating bowler object 1
Bowler b1 = new Bowler(obj.next(),obj.nextInt());
System.out.println(\"Enter name and score of bowler 2\");
//Creating bowler object 2
Bowler b2 = new Bowler(obj.next(),obj.nextInt());
System.out.println(\"Bowler 1 \"+b1);
System.out.println(\"Bowler 2 \"+b2);
}
}

INPUT :

Mcgrath 14
Boult 12

OUTPUT :

Enter name and score of bowler 1
Enter name and score of bowler 2
Bowler 1 Mcgrath : 14
Bowler 2 Boult : 12

Suppose you have already written the class for a Bowler. The Bowler class has two fields, a full name and a high score. Write the main() method to create two in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site