Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class MohamedI007PA3 { /** * User asked to create an address book. If no, the program exits with an exit message; otherwise, if yes,

public class MohamedI007PA3 {

/**

* User asked to create an address book. If no, the program exits with an exit message;

otherwise, if yes, the program proceeds to capturing the user's name, addressee's name, address,

and phone number. The information is stored in a String object specific to whether the addressee is family

or friend. After an entry for an addressee is complete, the user is prompted to continue with another

address or not. If the user doesn't want to continue, then the address book is printed.

*/

private staticScanner input = new Scanner (System.in);

private static String name;

private static String addressee;

private static String street;

private static String cityStateZip;

private static String phone;

private static StringBuilder phoneFormatted;

private static int relationship;

private static String family;

private static String friend;

public static void main(String[] args) {

char another;

setName();

setAddressee();

setStreet();

setCityStateZip();

setPhone();

StringBuilder phoneFormatted;

setRelationship();

String family = String.format("%nFAMILY%n");

String friend = String.format("%nFRIENDS%n");

System.out.printf("%nBegin entering addresses?'Y' or 'N':");

another = input.nextLine().charAt(0);

if (Character.toUpperCase(another) != 'Y')

{

System.out.printf("%nExiting program.");

}//End if Statement

System.out.printf("%nDo you want to enter another address?'Y' or 'N':");

input.nextLine();

another = input.nextLine().charAt(0);

if (Character.toUpperCase(another) != 'Y')

{

System.out.printf("%nADDRESS BOOK FOR %S%n", name);

System.out.printf( family + friend);

}//End if

} // End main methood

public static String setName()

{

System.out.printf("%nEnter your name:");

return input.nextLine();

} // End setName method

public static String setAddressee()

{

System.out.printf("%nEnter the name of the addressee:");

return input.nextLine();

} // End setAddressee method

public static String setStreet()

{

System.out.printf("%nEnter the street for %s:", addressee);

return input.nextLine();

} // End setStreet method

public static String setCityStateZip()

{

System.out.printf("%nEnter the city, state, and zip code for %s in the correct format:");

return input.nextLine();

} // End setCityStateZip method

public static String setPhone()

{

System.out.printf("%nEnter the phone number for %s inclduing area code:");

return input.nextLine();

phoneFormatted = new StringBuilder(phone);

phoneFormatted.insert(3, '-');

phoneFormatted.insert(7, '-');

return input.nextLine();

} // End setPhone method

public static int setRelationship()

{

System.out.printf("%nRelationship of addressee:%n"

+ "%n1. Family"

+ "%n2. Friends"

+ "%n%nChoose from the above:");

return input.nextInt();

if (relationship == 1)

{

family += String.format ("%nAddressee:%s"

+ "%nStreet:%s"

+ "%nCity, State Zip:%s"

+ "%nPhone:%s%n",addressee, street, cityStateZip, phoneFormatted);

}//End if

else

{

friend += String.format ("%nAddressee:%s"

+ "%nStreet:%s"

+ "%nCity, State Zip:%s"

+ "%nPhone:%s%n",addressee, street, cityStateZip, phoneFormatted);

}//End if else

} // End setRelationship method

} // End class MohamedI007PA3

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

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions