Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Below is the UML diagram for the class. Note: The instructions, variables and general information pertaining to the main method is not presented in the

Below is the UML diagram for the class. Note: The instructions, variables and general information pertaining to the main method is not presented in the UML but will be below. FriendsAndFamily + getSize(Scanner sc) : Object[] + friendOrFamily(Scanner sc) : int + getName (Scanner sc, int t) : String + getRelation(Scanner sc, String n) : String + getTimeKnown(Scanner sc, String n) : int + display(Object[] faf) : void As these methods are part of the main class, you can assume all of the above methods are static In the FriendsAndFamily class: 1. In the main method, create the following variables: A. Scanner B. Object Array named friendsAndFamily (Declare but do not assign) C. Friend object (Declare but do not assign) i.e. -> Friend fri; D. Family object (Declare but do not assign) E. String name F. String relation G. int timeKnown H. int type 2. Write the following functionality for each of the methods: Remember to check the UML for return type and parameters A. getSize ( ) I. Create integer size II. Use a validation loop to ensure size is positive III. Create an object array based on user-defined size variable IV. Return the array B. friendOrFamily ( ) I. Ask user if they are entering a friend or family member (String) II. Determine which String is entered (case does not matter) this information will be used with the type variable created earlier: If friend return 0 If family return 1 Otherwise, return 2 CIT244 Winyard C. getName ( ) I. Using the t variable passed, use a control structure to determine: If t is 0 prompt for friend input If t is 1 prompt for family input Otherwise, end the program with a System.exit(0) II. Read in the given name using .next() III. Clear the buffer if needed (.nextLine()) Further info on buffer issues: https://www.youtube.com/watch?v=hVoYpa_ryl0&list=PLDLzQoPnlK2Z-ZqfkJXyiv7GjgNdocmyO&index=11 IV. Return the given name D. getRelation ( ) I. Prompt user for their relation to given name II. Return relation variable (String) E. getTimeKnown ( ) I. Prompt user the length they have known their given friend II. Return integer variable for time known F. display ( ) I. Using an enhanced for loop, loop through the given object array printing the toString for each iteration 3. Back in the main method, use a for loop pertaining to the length of the object array, within this loop: A. Assign type to the method friendOrFamily B. If type is 0 then: I. Assign name to getName passing the appropriate variables II. Assign timeKnown to getTimeKnown passing the appropriate variables III. Assign fri to a new Friend object passing the appropriate variables IV. Assign the ith element of the array to fri C. If type is 1 then: I. Repeat the above, but instead of getTimeKnown call the relation method. II. Assign fam to a new Family object (not fri) III. Assign the ith element of the array to fam D. If type is NOT 0 or 1 then state you are ending the program due to invalid input and end using a System.exit(0) 4. Outside of the loop call the display method passing the object array

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

Students also viewed these Databases questions

Question

Compare a delusion with a hallucination.

Answered: 1 week ago