Question: package introToclasses; 1 * * A class is a blueprint describing objects in terms of the data they have and the methods that can be
package introToclasses;
A class is a blueprint describing objects in terms of the data they have and the methods that can be acted on them. The methods change the objects data.
The data is anything that describes the object up to you
Methods are functions but can only be called invoked on an object
and they can change the attributes values of those variables of that object
To create an object, we instantiate the class we create an istance of the class
ClassName objectName new ClassNameparams;
ClassName acts as a new type
Let's create a class for course
Always name your classes with the first letter capital
public class Course
String name;
String instructor;
int numberstudents;
String description;
int credits;
a mthod to display the values of all these variables:
void print
System.out.printlnName:
this.name;
System.out.printlnInstructor: this.instructor;
System.out.println Credits: this.credits;
System.out.printlnNumber registered: this.numberstudents;
System.out.printlnDecription: this.description;
void addStudent
increment number student. Always use this.variableName
will later why.
System.out.printlnAdding one student to
this.name;
this. numberstudents;
void dropstudent
System.out.printlnDropping one student from
this.name;
this numberstudents;
Design a method to change the instructor's name, with a new name.
changeInstructor accepts a string as the new name.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
