Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Background Course offerings at RIT are fully identified by three data fields. Th

ID: 3704139 • Letter: B

Question

Background Course offerings at RIT are fully identified by three data fields. The first identifies the department code, the second identifies the course, and the third identifies the section. For example ISTE-120-03 describes section 03 of course 120 in department ISTE. In addition to this information, course offerings also have an assigned credit value, and sometimes a textbook list. Problem Create a TestCourse class containing a main () method that will instantiate an object from a Course class. The requirements are broken down into 3 levels (see grading rubric, last two pages).t is recommended that the code be written in stages; i.e. complete level 1 before moving on to level 2, etc. Note that the 10-point bonus may be accomplished at any level. Level 1 Requirements (78 points): . Course class: . Has the following String attributes: o departmentCode o courseNumber o sectionNumber Has the following integer attribute: o studentCredit . Has mutators and accessors for all the above attributes . Has a default constructor that sets the attributes to the following values: o departmentCode: "0000" o courseNumber: "000" o sectionNumber: "00" o studentCredit: 0 .Has a parameterized constructor that accepts values to set departmentCode, courseNumber, and sectionNumber and also sets studentCredit to zero. TestCourse class: . Has a main() method . Has separate prompts for departmentCode, courseNumber, and sectionNumber Creates an object of Course named coursel using a parameterized constructor . Prompts for student credit for coursel and uses a mutator to set this value . Prints out a summary of information stored in coursel using the object's accessors Must validate user input for departmentCode, courseNumber sectionNumber, and studentCredit o o o o departmentCode must be 4 characters long courseNumber must be 3 characters long sectionNumber must be 2 characters long studentCredit must be greater than or equal to zero Practical 3 ISTE-120 Page 2 of 8

Explanation / Answer

Level 1 and 2

import java.io.*;
public class TestCourse//::public Course
{
     public static void main(String []args){

Course c=new Course();
c.print();
String d1=new String();
String cno=new String();
String sec=new String();
String i=new String();
int cr=0;
InputStreamReader sysIn = new InputStreamReader(System.in);
BufferedReader input = new BufferedReader(sysIn);
try{
System.out.println("Enter department code");
d1=input.readLine();
if(d1.length()<4)
throw new java.lang.Error("Department code should be of 4 charcters");
System.out.println("Enter Course Number");
cno=input.readLine();
if(cno.length()<3)
throw new java.lang.Error("course should be of 3 charcters");
System.out.println("Enter Section ");
sec=input.readLine();
if(sec.length()<2)
throw new java.lang.Error("Section should be of 2 charcters");
}
catch (IOException err) {
   
}
Course course1=new Course(d1,cno,sec);
course1.print();
try{
System.out.println("Enter credit hourse");
i=input.readLine();
cr=Integer.parseInt(i);
if(cr<0)
throw new java.lang.Error("Credit must be more than 0");
course1.passcredit(cr);
}
catch (IOException err) {
}

String identifier=d1.concat("-");
identifier=identifier.concat(cno);
identifier=identifier.concat("-");
identifier=identifier.concat(sec);
Course course2=new Course(identifier);
course2.passcredit(cr);
course1.print();
}
}

public class Course
{
String dep_code, c_no, sec_no;      // department code, course number and section number
int credit;             // Studentcredit
String fullCourseIdentifier;
Course(String i)
{
    fullCourseIdentifier=i;
    dep_code=i.substring(1,4);
    c_no=i.substring(6,3);
    sec_no=i.substring(10,2);
       credit=0;
}

Course()
{
dep_code="0000";
c_no="000";
sec_no="00";
credit=0;
}
public Course(String d, String c, String s)
{
    dep_code=d;
c_no=c;
sec_no=s;
credit=0;

}
void passcredit(int x)
{
    credit=x;
}
void print()
{
        System.out.println("Department Code"+dep_code);
        System.out.println("Course"+ c_no);
        System.out.println("Section"+sec_no);
        System.out.println("Credit" +credit);
        System.out.println("Course " +fullCourseIdentifier);

    }
}