Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have a code in Java, and would like help with all the errors. /** * Separate address books can be created for family, friends,

I have a code in Java, and would like help with all the errors.

/** * Separate address books can be created for family, friends, and work. User is * prompted for addressees and their relationship to the user who is the owner of * the address book. The entries are validated then added to the correct address * book. The address books are then printed. */

public static void main(String[] args) { // Initialize your local (method-level) variables to their default values in // your program. Scanner input = new Scanner(System.in); String ownerName; String addresseeName; String streetAddress; String cityStateZip; String phone; String relationship; String bookType; String addMore;

// Initializing address book for family and friends as empty string String familyBook = ""; String friendBook = ""; String businessBook = "";

// Prompt the user for their name and store it in a variable System.out.print("Enter your name: "); ownerName = input.nextLine();

// Prompt the user for the type of address book they would like to create System.out.print("What type of address book would you like to create? (family/friends/business): "); bookType = input.nextLine().toLowerCase();

// Keep prompting the user for addressees and their information until they // choose to stop do { // Prompt the user for the addressee's name and store it in a variable System.out.print("Enter the addressee's name: "); addresseeName = input.nextLine();

// Prompt the user for the street address and store it in a variable System.out.print("Enter the street address: "); streetAddress = input.nextLine();

// Prompt the user for the city, state, and zip code and store it in a variable System.out.print("Enter the city, state, and zip code: "); cityStateZip = input.nextLine();

// Prompt the user for the phone number and store it in a variable System.out.print("Enter the phone number: "); phone = input.nextLine();

// Prompt the user for the relationship to the owner and store it in a variable System.out.print("Enter the relationship to the owner: "); relationship = input.nextLine();

// Validate the input and add it to the appropriate address book if (bookType.equals("family")) { familyBook += " Addressee: " + addresseeName + " Street: " + streetAddress + " City, State Zip: " + cityStateZip + " Phone: " + phone + " "; } else if (bookType.equals("friends")) { friendBook += " Addressee: " + addresseeName + " Street: " + streetAddress + " City, State Zip: " + cityStateZip + " Phone: " + phone + " "; } else if (bookType.equals("business")) { businessBook += " Addressee: " + addresseeName + " Street: " + streetAddress + " City, State Zip: " + cityStateZip + " Phone: " + phone + " "; } else { System.out.println("Invalid book type."); }

// Prompt the user to add more addresses or stop

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

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions

Question

2. Why has the conflict escalated?

Answered: 1 week ago