public class Driver {   /** * @param args */   static Scanner keyboard = new Scanner(System.in);   publicstaticvoid main(String[] args) {   Mailbox[] mailboxes = new Mailbox[5];   Mailbox mailbox1 = new Mailbox("gmail"); Mailbox mailbox2 = new Mailbox("outlook"); Mailbox mailbox3 = new Mailbox("icloud");   mailboxes[0] = mailbox1; mailboxes[1] = mailbox2; mailboxes[2] = mailbox3;   Email email1 = new Email(); email1.setDate(new Date(2022, 11, 5)); email1.setSubject("Exam2 guidelines ");   Email email2 = new Email(new Date(2021, 3, 5), true, "Quiz3 in Ch7"); Email email3 = new Email(); email3.setDate(new Date(2020, 11, 3)); email3.setSubject("Late submission policy");   mailbox2.addEmail(email1); mailbox2.addEmail(email2); mailbox2.addEmail(email3);   // System.out.println("Hello! What would you like to do ");   intselection = displayMenu();   while (selection != 5) { // selection = displayMenu(); switch (selection) {   case 1:   System.out.print("Enter the client: "); String emailClient = keyboard.next(); Mailbox mailbox = findMailbox(emailClient, mailboxes); if (mailbox != null) { System.out.println(mailbox.toString()); } else { System.out.println("Mailbox not found. ");   }   break;   case 2:   System.out.print("For which client? "); String emailProvider = keyboard.next(); mailbox = findMailbox(emailProvider, mailboxes); if (mailbox == null) { System.out.println("Mailbox not found.");   } else { System.out.println("Enter email information on one line as follows: "); System.out.println(", , , , "); booleanisUrgent = keyboard.nextBoolean(); intmonth = keyboard.nextInt(); intday = keyboard.nextInt(); intyear = keyboard.nextInt(); String messageReceived = keyboard.next(); Email email = new Email(new Date(year, month, day), isUrgent, messageReceived); mailbox.addEmail(email); System.out.println("Email added successfully.");   }   break;   case 3:   System.out.print("For which client?"); String emailService = keyboard.next(); mailbox = findMailbox(emailService, mailboxes); if (mailbox == null) { System.out.println("Mailbox not found."); } else { System.out.print("For which year?"); intyear = keyboard.nextInt(); Email[] emailsByYear = mailbox.findEmail(year); if (emailsByYear.length == 0) { System.out.println("No emails found for this year."); } else { System.out.println("Found " + emailsByYear.length + " email(s):"); for (inti = 0; i < emailsByYear.length; i++) { System.out.println("Email info: " + emailsByYear[i].toString()); } } }   break;   case 4:   System.out.print("For which client?"); String emailInboxes = keyboard.next(); mailbox = findMailbox(emailInboxes, mailboxes); if (mailbox == null) { System.out.println("Mailbox not found."); } else { System.out.print("For which year?"); intyear = keyboard.nextInt(); Email[] emailsByYear = mailbox.findEmail(year); if (emailsByYear == null) { System.out.println("No emails found for this year."); } else { System.out.println("Found " + emailsByYear.length + " email(s):"); for (inti = 0; i < emailsByYear.length; i++) { System.out.println("Email info: " + emailsByYear[i].toString()); } } }   break;   case 5: System.out.println("Goodbye! "); break; default: System.out.println("Invalid input\n");   break;   }   selection = displayMenu(); } }   privatestaticint displayMenu() { System.out.println("Hello! What would you like to do? "); System.out.println("1- List Emails in a mailbox"); System.out.println("2- Add an email to a mailbox"); System.out.println("3- Search for an email in a mailbox by year"); System.out.println("4- Sort emails in a mailbox by year"); System.out.println("5 - quit\n"); System.out.print("Enter your choice: "); intselection = keyboard.nextInt(); keyboard.nextLine(); returnselection;   }   privatestatic Mailbox findMailbox(String client, Mailbox[] mailboxes) { for (inti = 0; i < mailboxes.length; i++) { if (mailboxes[i].getClient().equals(client)) { returnmailboxes[i]; } } returnnull; } Why is program not printing goodbye message when I enter 5?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

public class Driver

{

 

/**

* @param args

*/

 

static Scanner keyboard = new Scanner(System.in);

 

publicstaticvoid main(String[] args)

{

 

Mailbox[] mailboxes = new Mailbox[5];

 

Mailbox mailbox1 = new Mailbox("gmail");

Mailbox mailbox2 = new Mailbox("outlook");

Mailbox mailbox3 = new Mailbox("icloud");

 

mailboxes[0] = mailbox1;

mailboxes[1] = mailbox2;

mailboxes[2] = mailbox3;

 

Email email1 = new Email();

email1.setDate(new Date(2022, 11, 5));

email1.setSubject("Exam2 guidelines ");

 

Email email2 = new Email(new Date(2021, 3, 5), true, "Quiz3 in Ch7");

Email email3 = new Email();

email3.setDate(new Date(2020, 11, 3));

email3.setSubject("Late submission policy");

 

mailbox2.addEmail(email1);

mailbox2.addEmail(email2);

mailbox2.addEmail(email3);

 

// System.out.println("Hello! What would you like to do ");

 

intselection = displayMenu();

 

while (selection != 5)

{

// selection = displayMenu();

switch (selection)

{

 

case 1:

 

System.out.print("Enter the client: ");

String emailClient = keyboard.next();

Mailbox mailbox = findMailbox(emailClient, mailboxes);

if (mailbox != null)

{

System.out.println(mailbox.toString());

} else

{

System.out.println("Mailbox not found. ");

 

}

 

break;

 

case 2:

 

System.out.print("For which client? ");

String emailProvider = keyboard.next();

mailbox = findMailbox(emailProvider, mailboxes);

if (mailbox == null)

{

System.out.println("Mailbox not found.");

 

} else

{

System.out.println("Enter email information on one line as follows: ");

System.out.println("<urgent>, <m>, <d>, <y>, <Msg>");

booleanisUrgent = keyboard.nextBoolean();

intmonth = keyboard.nextInt();

intday = keyboard.nextInt();

intyear = keyboard.nextInt();

String messageReceived = keyboard.next();

Email email = new Email(new Date(year, month, day), isUrgent, messageReceived);

mailbox.addEmail(email);

System.out.println("Email added successfully.");

 

}

 

break;

 

case 3:

 

System.out.print("For which client?");

String emailService = keyboard.next();

mailbox = findMailbox(emailService, mailboxes);

if (mailbox == null)

{

System.out.println("Mailbox not found.");

} else

{

System.out.print("For which year?");

intyear = keyboard.nextInt();

Email[] emailsByYear = mailbox.findEmail(year);

if (emailsByYear.length == 0)

{

System.out.println("No emails found for this year.");

} else

{

System.out.println("Found " + emailsByYear.length + " email(s):");

for (inti = 0; i < emailsByYear.length; i++)

{

System.out.println("Email info: " + emailsByYear[i].toString());

}

}

}

 

break;

 

case 4:

 

System.out.print("For which client?");

String emailInboxes = keyboard.next();

mailbox = findMailbox(emailInboxes, mailboxes);

if (mailbox == null)

{

System.out.println("Mailbox not found.");

} else

{

System.out.print("For which year?");

intyear = keyboard.nextInt();

Email[] emailsByYear = mailbox.findEmail(year);

if (emailsByYear == null)

{

System.out.println("No emails found for this year.");

} else

{

System.out.println("Found " + emailsByYear.length + " email(s):");

for (inti = 0; i < emailsByYear.length; i++)

{

System.out.println("Email info: " + emailsByYear[i].toString());

}

}

}

 

break;

 

case 5:

System.out.println("Goodbye! ");

break;

default:

System.out.println("Invalid input\n");

 

break;

 

}

 

selection = displayMenu();

}

}

 

privatestaticint displayMenu()

{

System.out.println("Hello! What would you like to do? ");

System.out.println("1- List Emails in a mailbox");

System.out.println("2- Add an email to a mailbox");

System.out.println("3- Search for an email in a mailbox by year");

System.out.println("4- Sort emails in a mailbox by year");

System.out.println("5 - quit\n");

System.out.print("Enter your choice: ");

intselection = keyboard.nextInt();

keyboard.nextLine();

returnselection;

 

}

 

privatestatic Mailbox findMailbox(String client, Mailbox[] mailboxes)

{

for (inti = 0; i < mailboxes.length; i++)

{

if (mailboxes[i].getClient().equals(client))

{

returnmailboxes[i];

}

}

returnnull;

}

Why is program not printing goodbye message when I enter 5?

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education