Question

You have been hired by the CS Department to write code to help synchronize a professor and his/her students during office hou

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//compile it and run.

public class Demo
{
public static void main(String[]args)
{
System.out.println("Welcome to the lecture !!!\n");

Classroom c = new Classroom();
Professor p = new Professor();
c.setProf(p);
p.setClass(c);

Student s1 = new Student("S1", "germany",c);
Student s2 = new Student("S2", "england",c);
Student s3 = new Student("S3", "USA",c);
Student s4 = new Student("S4", "India",c);
Student s5 = new Student("S5", "China",c);
s1.start();
s2.start();
s3.start();
s4.start();
s5.start();

}


}

class Classroom
{
Professor prof;

public void setProf(Professor p)
{
prof = p;
}

public synchronized void currentStudent(String msg, String name)
{
System.out.println(name + " says : " + msg);
prof.answer(name);
System.out.println("\n");
}

}

class Student extends Thread
{
String name;
String ques;
Classroom cl;

Student(String n, String q, Classroom c)
{
name = n;
ques = q;
cl = c;
}

public void run()
{
String message = "Sir where is " + ques + " ? ";

for(int i = 0; i < 3; i++) // ask the same question 3 times !
{
cl.currentStudent(message, name);
//ask a question and wait or sleep before you ask again.

try
{
Thread.sleep(1500); // sleep for 1.5 sec.
}catch(Exception ex){System.out.println("error : " + ex);}

}

}//run


}

class Professor
{
String pro = "Nutty Prof";
Classroom cl;
String ans = "I dont know !";

public void setClass(Classroom c)
{
cl = c;
}

public void answer(String name)
{
System.out.println("PROF says : Dear " + name + " " + ans);
}

}

Add a comment
Know the answer?
Add Answer to:
You have been hired by the CS Department to write code to help synchronize a professor...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • One stakeholder I identify in the New Jersey City University setting are the professors or teachers....

    One stakeholder I identify in the New Jersey City University setting are the professors or teachers. Professor and teachers are at the frontline in the education system and serve an important role in the way education is given to students. As a student I believe professors can encourage and bring out the best in students. Just as I believe professors can bring out the best in student, I believe they can they can bring the worst out of students. From...

  • PLEASE USE BASIC C++ CODE PLEASE USE BASIC C++ CODE PLEASE HAVE DONE AS SOON AS...

    PLEASE USE BASIC C++ CODE PLEASE USE BASIC C++ CODE PLEASE HAVE DONE AS SOON AS POSSIBLE THANK YOU I REALLY APPRECIATE IT FILE TEXT: Mary 80 90 75 90 85 Joe 80 65 80 80 80 Same program as Quiz #4, but this time it must be done with arrays: Write a program that calculates the average of 5 test scores for each student on the file. Function 1--write a function to read the student's name 5 test scores...

  • In the following study, three different universities have been tracking a select group of professors over the course of their employment at that university to determine the number of students who are...

    In the following study, three different universities have been tracking a select group of professors over the course of their employment at that university to determine the number of students who are in a particular professor’s classes, how many of those students have graduated, and if any of them have had their work published. In the attached Excel file, Probabilities, are the totals for each of the professors at the three different universities that participated in the study. Note: Be...

  • Problem 1.4 You are lost in the basement of the Photonics center where the population is...

    Problem 1.4 You are lost in the basement of the Photonics center where the population is entirely composed of students and professors. You are looking for the exit, which you've decided is equally likely to be to the East or to the West. The students comprise two-thirds of the population, and any one student gives a correct answer to a request for directions with probability 3/4. (Assume answers to repeated questions are independent, even if the question and the person...

  • .Need code for my java class !! Write a simple java program that uses loops. You...

    .Need code for my java class !! Write a simple java program that uses loops. You may use ‘WHILE’ or ‘FOR’ or ‘DO-WHILE’ – you decide. The program should use a loop to compute the semester average for up to 5 students. In the loop the user will ask for a student name and their 3 test scores and add them up and divide the total by 3 giving the semester average. You will print out the student name and...

  • You have been approached by a University for the design and implementation of a relational databa...

    You have been approached by a University for the design and implementation of a relational database system that will provide information on the courses it offers, the academic departments that run the courses, the academic staff and the enrolled students. The system will be used mainly by the students and the academic staff. The requirement collection and analysis phase of the database design process provided the following data requirements for the University Database system. Using the following requirements answer this...

  • Please help. I need a very simple code. For a CS 1 class. Write a program...

    Please help. I need a very simple code. For a CS 1 class. Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "printall" - prints all student records (first name, last name, grade). "firstname name" - prints all students with...

  • You have been asked to write a program to grade several multiple-choice exams. The exam has...

    You have been asked to write a program to grade several multiple-choice exams. The exam has 20 questions, each answered with a letter in the range of ‘a’ through ‘f’. The answers key is declared in the program as constant of type string. An example of answer key is “abcdefabcdefabcdefab”. Your program should work for any other answer key. The program should first ask users for the number of students to be graded. Then it should have a while loop...

  • 6.You have been hired to conduct a survey that will predict the results of the next...

    6.You have been hired to conduct a survey that will predict the results of the next provincial election in Manitoba. You call 1,200 people in Winnipeg and ask them what party they intend to vote for in the upcoming election, and based on their responses you predict that the Green Party will win. The Green Party does not win the election. Which of the following most likely led to the failure of your survey to predict the election results? The...

  • CS 2050 – Programming Project # 1 Due Date: Session 3 (that is, in one week!)....

    CS 2050 – Programming Project # 1 Due Date: Session 3 (that is, in one week!). Can be resubmitted up to two times until Session 6 if your first version is submitted by session 3. In this project, you create two classes for tracking students. One class is the Student class that holds student data; the other is the GradeItem class that holds data about grades that students earned in various courses. Note: the next three projects build on this...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT