From MSchwarz, 2 Weeks ago, written in Java.
Embed
  1. /**
  2.  * This program represents a Basketball player
  3.  * @MSchwarz
  4.  * 10/1/19
  5.  */
  6. import java.util.Scanner;
  7. public class BBall
  8. {
  9.     //Fields (aka Instance variables)
  10.     private String name;
  11.     private double pointsPer;
  12.     private double reboundsPer;
  13.     private double assistsPer;
  14.     private String position;
  15.     private boolean isAll;
  16.     private boolean Allstar;
  17.     //constructor
  18.      /*
  19.      * A constructor is the function definition of how to creat an object of a class
  20.      * The below example is a no args constructor as it takes no parameters in the parentheses
  21.      * The goal of the constructor is to assign all of the above fields to given
  22.      */
  23.     public BBall()
  24.     {
  25.     name = "John Smith";
  26.     pointsPer = 13.6;
  27.     reboundsPer= 6.7;
  28.     assistsPer = 7.8;
  29.     position = "Center";
  30.     }
  31.    
  32.     //This Constructor takes in a string as a parameter as well as 3 ints to represent age
  33.     //gradeLevel and homeroom
  34.    
  35.     public BBall(String n, double a, double gL, double hRN, String p )
  36.     {
  37.         name = n;
  38.         pointsPer = a;
  39.         reboundsPer = gL;
  40.         assistsPer = hRN;
  41.         position = p;
  42.     }
  43.    
  44.    
  45.     public String toString() {
  46.    
  47.         return "Student Name: " + name + "\n" + "Position: "  + position + "\n" + "points per game: " + pointsPer + "\n" + "rebounds per game: " +
  48.         reboundsPer + "\n" + "Assists per game: " + assistsPer + "\n" + "All Star Player: " +  isAll + "\n";
  49.     }
  50.     //Example of the Gerter method, returns if the value is true
  51.    
  52.     public String getName()
  53.     {
  54.     return name;
  55.     }
  56.     //returns true if the age is <18 false otherwise}
  57.    
  58.      public double getpointsPer()
  59.     {
  60.     return pointsPer;
  61.     }
  62.    
  63.     public double getreboundsPer()
  64.     {
  65.     return reboundsPer;
  66.     }
  67.    
  68.     public double getassistsPer()
  69.     {
  70.         return assistsPer;
  71.     }
  72.    
  73.     public String getPosition()
  74.     {
  75.     return position;
  76.     }
  77.    
  78.     public void setpointsPer(double newpointsPer)
  79.     {
  80.     pointsPer = newpointsPer;
  81.     }
  82.    
  83.     public void setreboundsPer(double newreboundsPer)
  84.     {
  85.     pointsPer = newreboundsPer;
  86.     }
  87.    
  88.     public void setassistsPer(double newassistsPer)
  89.     {
  90.     pointsPer = newassistsPer;
  91.     }
  92.    
  93.     public void setPosition(String newPosition)
  94.     {
  95.     position = newPosition;
  96.     }
  97.    
  98.     public void setName(String newName) //Header Format public RETURNTYPE methodName(PARAMETERTYPE paramvar)
  99.     {
  100.         name = newName;
  101.     }
  102.    
  103.     public boolean Allstar()
  104.     {
  105.         if (pointsPer >= 8)
  106.         {
  107.         isAll = true;
  108.         return isAll;
  109.         }
  110.         else
  111.         {
  112.         isAll = false;
  113.         return isAll;
  114.         }
  115.        
  116.     }
  117.    
  118.    
  119. }