I am   trying to make a java program with three threads. two representing client bob and Alice. a third thread representing a  mail server. make Alice check their mailbox every 5 second if their is a mail form bob, Alice should send one back and bob should do the same thing. Pre-load Alice's mailbox with one mail from Bob. For the next minute or so, Alice should check for mail every 5 seconds and Bob should check for mail every 3 seconds. If they receive a mail, they should send one back. The body of the first mail should say "Hello", the body of the second mail should say "Hello Hello", and so on. Design a Mail class that has fields From, To, Date, Body. here is what I have but Im lost

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

help I am   trying to make a java program with three threads. two representing client bob and Alice. a third thread representing a  mail server. make Alice check their mailbox every 5 second if their is a mail form bob, Alice should send one back and bob should do the same thing. Pre-load Alice's mailbox with one mail from Bob. For the next minute or so, Alice should check for mail every 5 seconds and Bob should check for mail every 3 seconds. If they receive a mail, they should send one back. The body of the first mail should say "Hello", the body of the second mail should say "Hello Hello", and so on. Design a Mail class that has fields From, To, Date, Body.

here is what I have but Im lost

 


public class mailserver2 extends Thread
{
public boolean maildeliverd;
public boolean maildeliverbob;

public void checkMail(){
  
try{
while (maildeliverd){
Thread.sleep(5000);

}
}
catch(Exception e){
System.out.print("mail not recieved");
}
System.out.print("mail recieved");
mailclass mc = new mailclass();
mc.Maila();

}

public void checkMailbob(){
try{
while (!maildeliverbob){
Thread.sleep(3000);

}
}
catch(Exception e){
System.out.print("mail not recieved");
}
System.out.print("mail recieved");
mailclass mc = new mailclass();
mc.Mailb();

send();

}

public void send(){
this.maildeliverd= true;
}

public void sendtobob(){

this.maildeliverd= true;
}

public static void main(String args[]) {
mailserver2 ms= new mailserver2();
new Thread(()->{ // alice checking for mail
ms.checkMail();
},"alice").start();

new Thread(() -> {
ms.checkMailbob();
}, "bob").start();

try {
Thread.sleep(3000);
} catch (Exception e) {}

new Thread(() -> {
ms.send();
}, "send").start();

}


}

 

public class mailclass extends mailserver2 {
public void Mailb() {
System.out.println("You sent a new message Bob");
System.out.println("To Alice");
System.out.println("From Bob");
System.out.println("The date is"); // how to make date ?
System.out.println("The message is " + "Hello"); //how to make loop for hello hello ??
  
}
public void Maila() {
System.out.println("from Bob");
System.out.println("to Alice");
System.out.println("The date is");//how to make date ??
System.out.println("The message is " + "Hello"); //how to make loop for hello hello ??
}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY