Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started