Naming Requirements:
These are the names you are required to use for your lab project. Make sure the letter casing is also the same (for example, Example.java is not the same as example.java).
Java file name: Student.java
Main class name: Student
MAKE SURE TO ONLY SUBMIT Student.java
Core Requirements:
In this lab, we will be creating our own Student class. Implement the following specification below to create the class.
Private Data Members:
String name
int points
Public Static Data Members:
int studentCount
Constructor:
public Student(String nameArg)
Set (name) to (nameArg)
Set (points) to 0
Increment (studentCount) by 1
Public Methods:
public String getName()
Returns the data member (name)
public int getPoints()
Returns the data member (points)
public void setPoints(int pointsArg)
Set (points) to (pointsArg)
public int utorStudent(Student otherStudent)
Increment (otherStudent)’s (points) by 1 (Hint: use the setPoints method)
Returns (otherStudent)’s (points) after increment
Now it’s time to test your Student class
Copy the provided file Classroom.java into your project’s source folder
Run the file and check your results
//CODE TO COPY
public class Student {
private String name;
private int points;
public static int studentCount;
public Student(String nameArg) {
this.name = nameArg;
this.points = 0;
studentCount++;
}
public String getName() {
return name;
}
public int getPoints() {
return points;
}
public void setPoints(int pointsArg) {
this.points = pointsArg;
}
public int utorStudent(Student otherStudent)
{
otherStudent.setPoints(points +
1);
return otherStudent.points;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
THE ABOVE METHOD JUST INCREMENTS OTHER STUDENTS POINT BY ONE
IF YOU WANT TO DECREMENT CURRENT STUDENTS POINT BY 1 AND INCREMENT OTHER STUDENTS POINT BY 1, THEN REPLACE utorStudent() METHOD WITH THIS METHOD:
public int utorStudent(Student otherStudent) {
this.setPoints(points-1);
otherStudent.setPoints(points +
1);
return otherStudent.points;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
EXPLANATION
public class Student {//creating a class Student.java
//private members name,points
private String name;
private int points;
//public static variable studentCount
public static int studentCount;
//Constructor with one argument nameArg
public Student(String nameArg) {
this.name = nameArg;//assign name
as nameArg
this.points = 0;//assigning points
as 0
studentCount++;//increment
studentCont by 1
}
//Public Methods
public String getName() {//method getName
return name;//returning name
}
//method get Points
public int getPoints() {
return points;//returns
points
}
//method setPoints
public void setPoints(int pointsArg) {
this.points = pointsArg;//set
points as pointArgs
}
//method utorStudent which takes otherStudent as
parameter
public int utorStudent(Student otherStudent) {
otherStudent.setPoints(points +
1);//set points of other student by 1 more point
return otherStudent.points;//return
he otherstudents point
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CHECKING THE METHODS USING Classroom.java
NOTE: HOPE YOU HAVE Classroom.java FILE , THE CODE INSIDE THE CLASSROOM.JAVA MAY BE DIFFERENET
public class Classroom {
public static void main(String[] args) {
Student s1 = new
Student("StudentName1");// creating a student with name
StudentName1
s1.setPoints(100);// set
points
System.out.println("Student name
using getName method " + s1.getName());
System.out.println("Student point
using getPoints method " + s1.getPoints());
Student other = new
Student("OtherName");
other.setPoints(99);
System.out.println("Other Student
name using getName method " + other.getName());
System.out.println("Other Student
point using getPoints method " + other.getPoints());
s1.utorStudent(other);
System.out.println("other students
point: "+other.getPoints());
System.out.println("Total number of
students: "+other.studentCount);
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
IF YOU HAVE ANY PROBLEM REGARDING THE SOLUTION PLEASE COMMENT BELOW I WILL DEFINETLY HELP YOU
Naming Requirements: These are the names you are required to use for your lab project. Make...
java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...
Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....
Write a full class definition for a class named Player , and containing the following members: A data member name of type string . A data member score of type int . A member function called setName that accepts a parameter and assigns it to name . The function returns no value. A member function called setScore that accepts a parameter and assigns it to score . The function returns no value. A member function called getName that accepts no...
Write the interface (.h file) of a class Player containing:A data member name of type string .A data member score of type int .A member function called setName that accepts a parameter and assigns it to name . The function returns no value.A member function called setScore that accepts a parameter and assigns it to score . The function returns no value.A member function called getName that accepts no parameters and returns the value of name .A member function called...
CompSci 251: Intermediate Computer Programming Spring 2017 -Java Lab 5 For this lab we will be looking at static, or class variables. Remember that where instances variables are associated with a particular instance, static variables are associated with the particular class. Specifically, if there are n instances of a class, there are n copies of an instance variable, but exactly one copy of a static variable (even when n = 0). Student - uniqueId : int - id: int -...
Write a program in Java that prompts a user for Name and id number. and then the program outputs students GPA MAIN import java.util.StringTokenizer; import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { String thedata = JOptionPane.showInputDialog(null, "Please type in Student Name. ", "Student OOP Program", JOptionPane.INFORMATION_MESSAGE); String name = thedata; Student pupil = new Student(name); //add code here ...
I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student { private String name; private double gpa; private int idNumber; public Student() { this.name = ""; this.gpa = 0; this.idNumber = 0; } public Student(String name, double gpa, int idNumber) { this.name = name; this.gpa = gpa; this.idNumber = idNumber; } public Student(Student s)...
Read through the code of the class Player, noting it has two instance variables, name and rank, which are of type String and three further instance variables won, drew and lost which are of type int. There is also an attribute of the class, points, which does not have a corresponding instance variable. Also note the constructor and methods of the class and what they do. TournamentAdmin class code: public class RankAdmin { /** * Constructor for objects of class...
Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person and Student represent individuals with a first and last name as String class variables, and Student has an additional int class variable that represents a ID number. The Roster class represents a group of people that are objects of either the Person or Student class. It contains an ArrayList. The Person class has been completed for you with class variables, a constructor, and a...
Add additional information to the student class below such as name, address, major, and contact information along with all the getters and setters (methods) needed to access all data. Submit your code along with a sample run of your program. Comment all your code. Cite any sources of information you use. Write a note on the process of completing the assignment in a Microsoft Word document. // ShowStudent.java // client to test the Student class class ShowStudent { public static...