Last active
March 28, 2016 06:35
-
-
Save abirAbuAsim/32e5be3dea1ac58e1a5c to your computer and use it in GitHub Desktop.
Learning about Class and Object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * This program shows how to create a class with only instance | |
| * variables in it, how to declare an object, how to manipulate an | |
| * instance variable and show their value. | |
| * | |
| * @author Abir Bin Ayub Khan A.K.A AbSak | |
| * @version March 28, 2016 | |
| * | |
| */ | |
| public class Cricketer1 { | |
| private String name; // holds the name of the cricket player | |
| private int runs; // total runs scored by a player | |
| private int wickets; // total wickets taken by the player | |
| public static void main(String[] args){ | |
| /* Declaring and instantiating an object */ | |
| Cricketer1 player1 = new Cricketer1(); | |
| /* Assigning values to the instance variables */ | |
| player1.name = "Sakib Al Hasan"; | |
| player1.runs = 100; | |
| player1.wickets = 80; | |
| /* Displaying the values of the instance variabless */ | |
| System.out.println("Player name: " + player1.name ); | |
| System.out.println("Total runs: " + player1.runs ); | |
| System.out.println("Total wickets taken: " + player1.wickets ); | |
| // a loop to simulate some matches by the player and show its output | |
| // start loop | |
| // get a random run of the match | |
| // get a random wicket of the match | |
| // print the run and wicket of that match | |
| // end loop | |
| // print the current total score and wicket of the player after all the matches | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment