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

For this problem, you will design classes suitable for storing information about

ID: 3634090 • Letter: F

Question

For this problem, you will design classes suitable for storing information about University instructors. The goal of the exercise is to demonstrate arranging classes in an inheritance hierarchy for maximum code-sharing.

The problem

There are three types of Instructor: Faculty, Lecturer, and Grad student.
At any time, an instructor can best be described by three quantities:

number of unread e-mail messages,
age,
number of eccentricities

An instructor should initially have zero unread mail and an initial number of eccentricities.

There are two measures of an instructor's current mood: Stress and Respect.

Stress— an instructor's stress level is the number of unread messages. However, Stress is never more than 1000.
Grad students are the exception. Their stress is 1.6 times the number of unread messages and their maximum stress is 1400.

Respect- generally an instructor's level of respect in the community is their age minus the number of eccentricities. Respect can never be negative.

Faculty are the exception—(Faculty eccentricities are regarded as "signs of a troubled genius" thereby increasing respect). So for faculty respect is age plus number of eccentricities.


Everything in an instructor's life is driven by receiving e-mail.
This is done by a call to the getMail( ) method. For example DrX.getMail(200); makes the Instructor DrX receive 200 new E-mails.

When an instructor gets new, un-read e-mail Several things happen:
First, the amount of unread-mail is increased. If, for example he had unreadEmail = 10 and he receives 23 new emails, unreadEmail becomes 10 + 23 = 33.

Second, 80% of the time, there will be no change in the number of eccentricities. 20% of the time the number of eccentricities will randomly go up or down by two.

Third, the new unread mail may cause the instructor's Stress factor to become larger than their Respect factor which makes the instructor unhappy.

When and if an Instructor becomes "unhappy", a "coping" mechanism is activated.

Instructors have different coping mechanisms.

Faculty react by gaining 40 eccentricities.

Lecturers react by accidentally deleting 70% of their unread mail.

Grad students react by reading all of their unread mail. The resulting mental anguish causes the Grad student's eccentricities to go up or down by three randomly.

The coping mechanisms may or may not bring the Stress and Respect factors back in line, however, the coping mechanism is activated at most one time for each batch of incoming mail. (this means that if after the coping mechanism is called, stress is still greater than respect you DO NOT call it again)

On the next page there is a sketch of a design drawing to help you think about your solution.
You will note that, the way to send an instructor mail is by calling his GetMail( int) method with an int parameter representing the number of email messages.
When called, method GetMail( ) takes care of updating the variables, calculating Stress and Respect and finally , if needed, calling the Cope( ) method.

As a testing mechanism, every time the GetMail method is called, it should display on the screen all the relevant quantities of the Instructor. i.e unreadMail, eccentricities, Stress, Respect. If it happens to call Cope() it should display that cope() was called then redisplay unreadMail and eccentricities. Implement your classes and test in a main() method as follows:

public static void main (String [ ] args) throws Exception {
Faculty DrX = new Faculty (34, 10); // the constructor takes an age
// and number of initial eccentricities a parameter
Lecturer MrY = new Lecturer (27, 4);
Grad Joe = new Grad (23, 2);
for(int k = 0 ; k < 10 ; k ++ ){
int mail = k*10 + 50;
DrX.GetMail( mail);
MrY.GetMail( mail);
Joe.GetMail(mail);
System.in.read();
}
}

Explanation / Answer

Dear...



class Instructor
{
private int age;
private int unreadMail;
private int eccentricities;
public final static int MAX_STRESS = 1000;

public Instructor(int anAge)
{
age = anAge; unreadMail = 0; eccentricities = 0;
}
public int get_age()
{
return age;
}
public int get_ecc()
{
return eccentricities;
}
public int stress()
{
return Math.min(unreadMail, MAX_STRESS);
}
public int respect()
{
return Math.max(age - eccentricities, 0);
}
public void receive_email(int numMessages)
{
unreadMail += numMessages;
if ( Math.random() < 0.1 )
random_mod_ecc();
}
public void random_mod_ecc()
{
eccentricities += Math.random() < 0.5 ? 1 : -1 ;
if ( eccentricities < 0 )
eccentricities = 0;
}

public void read_unreadMail()
{
while ( unreadMail > 0 ) unreadMail--;
}
public void deletehalf_unreadMail()
{
unreadMail /= 2;
}
public void increment_ecc(int incr)
{
eccentricities += incr;
}
}
private Instructor instr;

public Professor(int anAge)
{
instr = new Instructor(anAge);
}
public int stress()
{
return instr.stress();
}
public int respect()
{
return instr.get_age() + instr.get_ecc();
}
public void receive_email(int numMessages)
{
instr.receive_email(numMessages);
if ( stress() > respect() )
cope();
}
public void cope()
{
instr.increment_ecc(10);
}
}

private Instructor instr;

public Lecturer(int anAge)
{
instr = new Instructor(anAge);
}
public int stress()
{
return instr.stress();
}
public int respect()
{
return instr.respect();
}
public void receive_email(int numMessages)
{
instr.receive_email(numMessages);
if ( stress() > respect() )
cope();
}
public void cope()
{
instr.deletehalf_unreadMail();
}
}

class GradStudent
{
private Instructor instr;
public GradStudent(int anAge)
{
instr = new Instructor(anAge);
}
public int stress()
{
return 2 * instr.stress();
}
public int respect()
{
return instr.respect();
}
public void receive_email(int numMessages)
{
instr.receive_email(numMessages);
if ( stress() > respect() )
cope();
}
public void cope()
{
instr.read_unreadMail();
instr.random_mod_ecc();
}
}
public class instrs_compos
{
public static void main(String[] args)
{
Professor p_a = new Professor(45),
p_b = new Professor(44);
Lecturer l_a = new Lecturer(35), l_b = new Lecturer(34);
GradStudent g_a = new GradStudent(25),
g_b = new GradStudent(24);
int pas = p_a.respect();
l_b.receive_email(100);
g_a.receive_email(100);
}
}

abstract class Instructor

{

private int age;

private int unreadMail;

private int eccentricities;

public final static int MAX_STRESS = 1000;

public Instructor(int anAge) {

age = anAge; unreadMail = 0; eccentricities = 0;

}

public int get_age() { return age; }

public int get_ecc() { return eccentricities; }

public int stress() { return Math.min(unreadMail, MAX_STRESS); }

public int respect() { return Math.max(age - eccentricities, 0); }

public abstract void cope();

public void receive_email(int numMessages) {

unreadMail += numMessages;

if ( Math.random() < 0.1 ) // 10% of the time

random_mod_ecc();

if ( stress() > respect() )

cope();

}

public void random_mod_ecc() {

eccentricities += Math.random() < 0.5 ? 1 : -1 ;

if ( eccentricities < 0 )

eccentricities = 0;

}

public void read_unreadMail() { while ( unreadMail > 0 ) unreadMail--; }

public void deletehalf_unreadMail() { unreadMail /= 2; }

public void increment_ecc(int incr) { eccentricities += incr; }

}

public Lecturer(int anAge) { super(anAge); }

public void cope() { deletehalf_unreadMail(); }

}

public class instrs_abstr {

public static void main(String[] args) {

Professor p_a = new Professor(45), p_b = new Professor(44);

Lecturer l_a = new Lecturer(35), l_b = new Lecturer(34);

GradStudent g_a = new GradStudent(25), g_b = new GradStudent(24);

Instructor ia[] = new Instructor[6];

ia[0] = p_a;

ia[1] = p_b;

ia[2] = l_a;

ia[3] = l_b;

ia[4] = g_a;

ia[5] = g_b;

for ( int i = 0; i < 6; i++ )

ia[i].receive_email(100);

}

}

/* instrs_inherit.java */

class Instructor

{

private int age;

private int unreadMail;

private int eccentricities;

public final static int MAX_STRESS = 1000;

public Instructor(int anAge)

{

age = anAge; unreadMail = 0;

eccentricities = 0;

}

public int get_age()

{

return age;

}

public int get_ecc()

{

return eccentricities;

}

public int stress()

{

return Math.min(unreadMail, MAX_STRESS);

}

public int respect()

{

return Math.max(age - eccentricities, 0);

}

public void receive_email(int numMessages)

{

unreadMail += numMessages;

if ( Math.random() < 0.1 )

random_mod_ecc();

}

public void random_mod_ecc()

{

eccentricities += Math.random() < 0.5 ? 1 : -1 ;

if ( eccentricities < 0 )

eccentricities = 0;

}

public void read_unreadMail()

{

while ( unreadMail > 0 ) unreadMail--;

}

public void deletehalf_unreadMail()

{

unreadMail /= 2;

}

public void increment_ecc(int incr)

{

eccentricities += incr;

}

}

public Professor(int anAge) { super(anAge); }

public int respect() { return get_age() + get_ecc(); }

public void receive_email(int numMessages) {

super.receive_email(numMessages);

if ( stress() > respect() )

cope();

}

public void cope()

{

increment_ecc(10);

}

}

class Lecturer extends Instructor

{

public Lecturer(int anAge)

{

super(anAge);

}

public void receive_email(int numMessages)

{

super.receive_email(numMessages);

if ( stress() > respect() )

cope();

}

public void cope()

{

deletehalf_unreadMail();

}

}

class GradStudent extends Instructor

{

public GradStudent(int anAge)

{

super(anAge);

}

public int stress()

{

return 2 * super.stress();

}

public void receive_email(int numMessages)

{

super.receive_email(numMessages);

if ( stress() > respect() )

cope();

}

public void cope()

{

read_unreadMail();

random_mod_ecc(); }

}

public class instrs_inherit

{

public static void main(String[] args)

{

Professor p_a = new Professor(45),

p_b = new Professor(44);

Lecturer l_a = new Lecturer(35),

l_b = new Lecturer(34);

GradStudent g_a = new GradStudent(25),

g_b = new GradStudent(24);

Instructor ia[] = new Instructor[6];

ia[0] = p_a;

ia[1] = p_b;

ia[2] = l_a;

ia[3] = l_b;

ia[4] = g_a;

ia[5] = g_b;

for ( int i = 0; i < 6; i++ )

ia[i].receive_email(100);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote