Question
I developed the following code. But I need to have a driver method for it. How do I separate that out? One method should be
I developed the following code. But I need to have a driver method for it. How do I separate that out? One method should be in its separate file. This file is known as the class section and hold the attributes listed here and below in my program: CRN, Capacity, Course Number, Enrollment, Instructor ID, Department, Instructional mode, meeting time/days. The Driver program will allow you to enter the specific class. I have to keep the toString method and use a printf or println method to display the data out to the user.
/**
* Steven Rojano
* CIS 131
* Homework 6
* Classes and Objects
*
* */
import java.util.Scanner;
class ClassesAndObjects
{
//variable declaration
//non parameterised contructor
int CRN,Course_number,Capacity,Enrollment,Instructor_ID;
String Department,Instructional_mode,Meeting_days,Meeting_times;
// This is a constructor and not a method within this program
// This is also known as a no-argument constructor
// I am giving values to my int and string variables in this constructor
ClassesAndObjects()
{
CRN=0;
Course_number=0;
Capacity=0;
Enrollment=0;
Instructor_ID=0;
Department="";
Instructional_mode="";
Meeting_days="";
Meeting_times="";
} // ends constructor
// parameterised constructor that will hold the variables
// within the parenthesis
ClassesAndObjects (int a,int b,int c,int d,int e,String x,String y,String z,String q){
CRN=a;
Course_number=b;
Capacity=c;
Enrollment=d;
Instructor_ID=e;
Department=x;
Instructional_mode=y;
Meeting_days=z;
Meeting_times=q;
} // ends ClassesAndObjects constructor
void tostring(){
//displaying the values
System.out.println("CRN : "+CRN);
System.out.println("Department : "+Department);
System.out.println("Course number : "+Course_number);
System.out.println("Instructional mode : "+Instructional_mode);
System.out.println("Meeting days : "+Meeting_days);
System.out.println("Meeting times : "+Meeting_times);
System.out.println("Capacity : "+Capacity);
System.out.println("Enrollment : "+Enrollment);
System.out.println("Instructor's ID : "+Instructor_ID);
} // ends to string method
// main function
public static void main(String[] args){
// variable declaration
// The following variables are my CRN, course number, capacit, enrollment, and course instructor ID.
int crn,cn,ca,en,id;
// These are my string variables that will be used to display department, instructional mode,
// meeting days, and meeting times
String dep,im,md,mt;
Scanner sc=new Scanner(System.in);
//accepting the details from the user
// The user will enter the following informations and the program will store in memory and display the information at the
// end of the program
System.out.println("Enter the CRN");
crn=sc.nextInt();
System.out.println("Enter the Course number");
cn=sc.nextInt();
System.out.println("Enter the Capacity");
ca=sc.nextInt();
System.out.println("Enter the Enrollment");
en=sc.nextInt();
System.out.println("Enter the Instructor ID");
id=sc.nextInt();
System.out.println("Enter the Department");
dep=sc.next();
System.out.println("Enter the Instructional mode");
im=sc.next();
System.out.println("Enter the Meeting Days");
md=sc.next();
System.out.println("Enter the Meeting Times");
mt=sc.next();
//creatimg the object of the class
ClassesAndObjects obj = new ClassesAndObjects(crn,cn,ca,en,id,dep,im,md,mt);
System.out.println();
//calling the tostring function
obj.tostring();
} // end of main function
} // end of program
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