Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started