For this assignment you will create & submit 3 classes: 1. Family 2. Friend 3. FriendsAndFamily...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
For this assignment you will create & submit 3 classes: 1. Family 2. Friend 3. FriendsAndFamily (Main Class) Begin by creating a class named Family (This class will not have a main method) Below is the UML diagram for the class. Family - name: String - relation: String + Family(String n, String r) + toString(): String In the Family class: Data fields: name, is a global (instance) variable of type String relation, is a global (instance) variable of type String Constructor: There is no default constructor for this class The constructor will take two arguments (String n and String r) Use the "private = public" for each variable within the constructor o i.e. name = n Method: toString ( ) o Returns a neatly formatted String as seen in the images on the last page of this document (For FAMILY) Next, create a class named Friend (This class will not have a main method) Below is the UML diagram for the class. - name: String - timeKnown: int Friend + Friend(String n, int tk) + validateTimeKnown (int tk) : int +toString(): String In the Friend class: Data fields: name, is a global (instance) variable of type String timeKnown, is a global (instance) variable of type int Constructor: There is no default constructor for this class The constructor will take two arguments (String n and int tk) Use the "private = public" for the name variable within the constructor Assign the timeKnown variable to the validate Time Known method, passing tk Methods: Remember, refer to the UML diagram for arguments, public/private and return types validate TimeKnown ( ) Returns an integer value for timeKnown variable based on tk argument passed If the users defined argument is < 0 we assign timeKnown to 00 Otherwise, timeKnown is what the user passes to the method call toString() Returns a neatly formatted String as seen in the images on the last page of this document (For FRIEND) See next page for FriendsAndFamily class information & instructions Now, create a main class named FriendsAndFamily (This class will have a main method) 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. Now, create a main class named FriendsAndFamily (This class will have a ma method) Below is the UML diagram for the class. - Note: The instructions, variables and general information pertaining to the main metho 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. II. Create integer size 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. II. Ask user if they are entering a friend or family member (String) 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 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()) IV. Return the given name D. getRelation ( ) I. Prompt user for their relation to given name II. Return relation variable (String) E. getTimeKnown ( ) I. II. Prompt user the length they have known their given friend 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 friend OrFamily B. If type is 0 then: I. II. Assign name to getName passing the appropriate variables 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. II. Repeat the above, but instead of getTimeKnown call the relation method. Assign fam to a new Family object (not fri) III. Assign the ith element of the array to fam 4. Outside of the loop call the display method passing the object array. Images of programming Validate size of family is > 0 Note, negative year will result in 0 toString() method for friend class Output - CIT244 FA20 AC01 (run) x run: (Warning: When prompted for choice of "friend" or "family", anything other than friend or family will end the program) How many friends & family do you wish to enter? --> 0 How many friends & family do you wish to enter? --> 3 Is this a friend or family memember? --> FriEND Enter the name of this friend --> Tom How long have you known Tom --> -45 Is this a friend or family memember? --> FamiLY Enter the name of this family member --> Jane Enter your realtion to Jane --> First Cousin Is this a friend or family memember? --> Friend Enter the name of this friend --> Jake How long have you known Jake --> 12 Tom and you have you been friends for year(s). Case insensitive Notice different prompt shown for friend / family toString() method for friend class toString() method for family class Tom and you have you been friends for 0 year(s). Jane is part of your family, the realtionship is, First Cousin. Jake and you have you been friends for 12 year(s). BUILD SUCCESSFUL (total time: 26 seconds) Invalid input behavior run: (Warning: When prompted for choice of "friend" or "family", anything other than friend or family will end the program) How many friends & family do you wish to enter? --> 5 Is this a friend or family memember? --> family Enter the name of this family member --> Greg Enter your realtion to Greg --> father Is this a friend or family memember? --> pizza Invalid input. Program ending. BUILD SUCCESSFUL (total time: 47 seconds) For this assignment you will create & submit 3 classes: 1. Family 2. Friend 3. FriendsAndFamily (Main Class) Begin by creating a class named Family (This class will not have a main method) Below is the UML diagram for the class. Family - name: String - relation: String + Family(String n, String r) + toString(): String In the Family class: Data fields: name, is a global (instance) variable of type String relation, is a global (instance) variable of type String Constructor: There is no default constructor for this class The constructor will take two arguments (String n and String r) Use the "private = public" for each variable within the constructor o i.e. name = n Method: toString ( ) o Returns a neatly formatted String as seen in the images on the last page of this document (For FAMILY) Next, create a class named Friend (This class will not have a main method) Below is the UML diagram for the class. - name: String - timeKnown: int Friend + Friend(String n, int tk) + validateTimeKnown (int tk) : int +toString(): String In the Friend class: Data fields: name, is a global (instance) variable of type String timeKnown, is a global (instance) variable of type int Constructor: There is no default constructor for this class The constructor will take two arguments (String n and int tk) Use the "private = public" for the name variable within the constructor Assign the timeKnown variable to the validate Time Known method, passing tk Methods: Remember, refer to the UML diagram for arguments, public/private and return types validate TimeKnown ( ) Returns an integer value for timeKnown variable based on tk argument passed If the users defined argument is < 0 we assign timeKnown to 00 Otherwise, timeKnown is what the user passes to the method call toString() Returns a neatly formatted String as seen in the images on the last page of this document (For FRIEND) See next page for FriendsAndFamily class information & instructions Now, create a main class named FriendsAndFamily (This class will have a main method) 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. Now, create a main class named FriendsAndFamily (This class will have a ma method) Below is the UML diagram for the class. - Note: The instructions, variables and general information pertaining to the main metho 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. II. Create integer size 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. II. Ask user if they are entering a friend or family member (String) 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 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()) IV. Return the given name D. getRelation ( ) I. Prompt user for their relation to given name II. Return relation variable (String) E. getTimeKnown ( ) I. II. Prompt user the length they have known their given friend 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 friend OrFamily B. If type is 0 then: I. II. Assign name to getName passing the appropriate variables 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. II. Repeat the above, but instead of getTimeKnown call the relation method. Assign fam to a new Family object (not fri) III. Assign the ith element of the array to fam 4. Outside of the loop call the display method passing the object array. Images of programming Validate size of family is > 0 Note, negative year will result in 0 toString() method for friend class Output - CIT244 FA20 AC01 (run) x run: (Warning: When prompted for choice of "friend" or "family", anything other than friend or family will end the program) How many friends & family do you wish to enter? --> 0 How many friends & family do you wish to enter? --> 3 Is this a friend or family memember? --> FriEND Enter the name of this friend --> Tom How long have you known Tom --> -45 Is this a friend or family memember? --> FamiLY Enter the name of this family member --> Jane Enter your realtion to Jane --> First Cousin Is this a friend or family memember? --> Friend Enter the name of this friend --> Jake How long have you known Jake --> 12 Tom and you have you been friends for year(s). Case insensitive Notice different prompt shown for friend / family toString() method for friend class toString() method for family class Tom and you have you been friends for 0 year(s). Jane is part of your family, the realtionship is, First Cousin. Jake and you have you been friends for 12 year(s). BUILD SUCCESSFUL (total time: 26 seconds) Invalid input behavior run: (Warning: When prompted for choice of "friend" or "family", anything other than friend or family will end the program) How many friends & family do you wish to enter? --> 5 Is this a friend or family memember? --> family Enter the name of this family member --> Greg Enter your realtion to Greg --> father Is this a friend or family memember? --> pizza Invalid input. Program ending. BUILD SUCCESSFUL (total time: 47 seconds)
Expert Answer:
Related Book For
Modern Database Management
ISBN: 978-0133544619
12th edition
Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi
Posted Date:
Students also viewed these programming questions
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Isaiah wants to build a new shopping complex. Isaiah is afraid that once news gets out about his plans, the price of the land where he wants to build the shopping complex will increase in price....
-
Classify each of the following statements as true or false: (a) Substitutional alloys tend to be more ductile than interstitial alloys. (b) Interstitial alloys tend to form between elements with...
-
On December 31, 2024, when its Allowance for Doubtful Accounts had a debit balance of $1,371, Sandhill Co. estimates that 8% of its accounts receivable balance of $77,800 will become uncollectible...
-
Consider the hypotheses for the general linear model, which are of the form \[H_{0}: \mathbf{T} \beta=\mathbf{c}, \quad H_{1}: \mathbf{T} \beta eq \mathbf{c}\] where $\mathbf{T}$ is a $q \times p$...
-
On August 1, 2016, Rafael Masey established Planet Realty, which completed the following transactions during the month: a. Rafael Masey transferred cash from a personal bank account to an account to...
-
Whitney received $ 7 6 , 1 0 0 of taxable income in 2 0 2 3 . All of the income was salary from her employer. What is her income tax liability in each of the following alternative situations?
-
The Director of the Spanish Data Protection Agency requested, within his powers, the opening of inspection actions before the Ministry of Health and Consumer Affairs of the Autonomous Community of...
-
Suppose the market risk premium is 6.6% and the risk-free interest rate is 4.6%. Calculate the cost of capital of investing in a project with a beta of 1.4.
-
You are considering how to invest part of your retirement savings. You have decided to put $300,000 into three stocks: 60% of the money in GoldFinger (currently $23/share), 30% of the money in...
-
You own three stocks: 600 shares of Apple Computer, 10,000 shares of Cisco Systems, and 5000 shares of Colgate-Palmolive. The current share prices and expected returns of Apple, Cisco, and...
-
Consider two local banks. Bank A has 76 loans outstanding, each for $1 million, that it expects will be repaid today. Each loan has a 6% probability of default, in which case the bank is not repaid...
-
Consider the following two, completely separate, economies. The expected return and volatility of all stocks in both economies is the same. In the first economy, all stocks move togetherin good times...
-
Write a user-defined function that calculates grade point average (GPA) on a scale of 0 to 4, where A = 4 B = 3 C = 2 D = 1 E = 0 and . For the function name and arguments use av = GPA(g,h). The...
-
Differentiate the following terms/concepts: a. Personality types and money attitudes b. Planners and avoiders c. Moderating and adapting to biases d. "Perfectible judges" and "incorrigible judges"
-
The two surfaces of a double convex, thin lens made of plastic each have an absolute value of radius of curvature of \(1.8 \mathrm{~mm}\). If the focal length of the lens is \(4.5 \mathrm{~mm}\),...
-
The radius of curvature of one surface of a glass lens \((n=1.45)\) is \(1.50 \mathrm{~m}\). If sunlight is focused at a point \(0.300 \mathrm{~m}\) away from the lens, what is the radius of...
-
You have a thin lens that is convex on both surfaces. The material of which the lens is made has index of refraction \(n=1.40\), and the radii of curvature are \(\left|R_{1} ight|=300 \mathrm{~mm}\)...
Study smarter with the SolutionInn App