Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public static void main (Stringfil args) & fiprint top header ID Nate Gender Age CH Acadeaic Year 4i Student.printheader(); I* Creates a student and prints

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
public static void main (Stringfil args) \& fiprint top header ID Nate Gender Age CH Acadeaic Year 4i Student.printheader(); I* Creates a student and prints his info, - Parateters here arez Nane, age, nunber of courses enrolted in, * acadenic year, and pender. - Pay attention that the 10 is auto generated and does not have a setter. - valid age is (2100) othernise, it is set to 1 - valid acadenicrear is [1-10] otherwise, it is set to 1 * valid nunEarolledcourses is -[1-9] othendise, it is set to a if I/You must make this constructor call the enpty. constructor wilch sets the value of the id wakabe 5 tudent s1= sem 5 tudent (" Aherd A1,20,6,2) I f 4printstudentinfo() prints the ID, nase, Age, Credit Hours, Acadende year, and gender. * credit hours is the number of courses the student is enrolled in o 3 is 51.printstudent inta( ) //Creates a second student and prints the students' info BYou tast rake this constructor call the constructor that takes atl attributes but not the gender student 12 = new Student ("Radian A Aeer", 23, 5, 6, Gender.MALE); s2. printstudent Info( ) //Creates a third student and prints the students info Student 33= new student () : llsets the name of s3 to Aisha Faroz. 5ysten, out. prinitin("Setting the nane of p3 to "Aishs Favarl":); s3, sethane( "Atsta Fouaz"): (ISet numer of enrolled courses for Aisha to 4 Systen, out. printlin(-Setting nunber of enrotled courses of Aisha to 41 ); 53. setthueEnrolledcourses (4); 14printstudentinfol) for 53=1 s3.printstudent Tnfo( ): Z3set number of enrolied courses of Atsha to 10 ! Systeniout,printla("set enrotled courses to 1017 ): s3. printstudent Into (); //5ets the age of Asha to 19 System. out.printin("setting Aisha's age to 19 )i 53. setage(19): fisets the gender of Adsha to Fenate 53. setGender(Gender. FEMALE) 11. printstudentinfo () for s3 53. printstudintinfa(): / echecks if 51 and 53 having the sane values. for all of their corresponding attributese/ 5ysted, out, printin("s1. equats (53)7. Hi. equals (53)); lfcreates student object s4 Student 54 a new 5 tudent (): lacopies data of 51 to s4il sl. sogy(54) i 5ysten. out, printin("s4 is a copy of s1"): l+checks if sl and s4 having the sate vatues for all of their corresponding attributes*/ Systes. oet. printin("s1. equats (54)7 " " s1. equats (54)). ficreates a clone of 53 and returos its reference to be saved in 35. 455 is a clone of $3 if Student 35=sinsignel)s Systea. out,print In("s5 is a clane of 53)1 fochecks if 33 and 55 having the sase valies for atl of their corresponding attributes f Systes. out. pr int ln ( "s 3 .equats (35) ? " +13. equals (35)): loconpares 51 to 52 based on the value of the attribute id. if the value of id of st is less than the value of id of 52 the method returns 1. * If the value of id of s1 is greater than the vatue of id of st the enthod returns 1 . - othernise the twe vatues of id are, equal, it returns. +8 suitch(s1. compscetg(s2)) ( case 1t 5ystem. out. 0 inine in( s1. dan2. 1d") ibrenk: case es Systen.out. print la("s1. 1de=52. (a") ibreak; 1 liorints all atudents Systen, out.printla(): Student.prinflieader(is /fprunts att stuaents Systen.out.print hn(). student, printheader (): s2. pintstudentinfo(); 52.printstudentinfo(): s3. printstudentinfo( ; 34. printstudentinfa(): 55. Drintstudentinfa(): System.out.printin( "Intotal number of students ist " + student. tokalNume(students); 1. creating course objects. Wust nake use of constructors chainingt constructor catts another the course type can be THEORY, LAB, SEMINAR, SOP, TRADIDG Cgurse cl = nes cogrse() Cpurse c2= nes Course (MAAR333", Soursetyde. THEORY, 4); c1. setchs(1): c1.setCode("SPM11a"); c1. settittle("postgraduate Seninar")/ c1. setType(ursetyoe. SEMDAR): /kprinting header of course * Code Type cHs Title course.printheader():1 l/print all courses taking advantage of overriding tostring nethod Systen, out.print ln(c1) : systen, out,print lnfe2li Systen. out.print in (c3); llorint number of courses Systen. out.printin("total number of courses is "+Sourse, tothunofcourses); P= - croating instructor objects. Mast eake use of constructors chainings constructor calts another Instcuctor il 11 bew instructor() Instoucter, i2 aeu inftrygitor "Huda Inran", 1234); insktistot 13= ned Instrugtor("Riyad Asad", 6326, "r. asadequ.edu. 9a"): 11. setiate("Maza-Ibrahin") ) 11. seteaploynent Io(5555): /*printing header of Instructor if Instructor. printheaderfi): Alsprictoc.printheaderfil all instructors taking advantage of overriding tostring eethod System, out.printin(i1): Systen, out,print in (12): Systea,out.printin (13); System. out.print in("Total nurber of courses is "+ Anst rugitar. tothumofinstructors): l/print nueber of instructors

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

How to find if any no. is divisble by 4 or not ?

Answered: 1 week ago

Question

Explain the Pascals Law ?

Answered: 1 week ago

Question

What are the objectives of performance appraisal ?

Answered: 1 week ago