Create a Post Class Create a new class called Post and fill in the comment details....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Create a Post Class Create a new class called Post and fill in the comment details. This class represents a single "post" or "message" on a message sharing service like Twitter or Facebook. For this lab assignment, a Post) is defined primarily by its attributes. For each of the attributes below, you must: 1. Declare a field with the given name and type. 2. Define a getter method (accessor) for the field. Note that the attributes of a Post are read-only and no setters are provided. Once the post is created, the values specified in the constructor become the "permanent" values for the fields. In this particular model, you can't go back and "edit" posts after they have been made by calling setter methods. This is a design choice for this model, but when creating your own classes on your own projects, you always have the freedom to decide whether or not a setter (or even a getter) is appropriate or not. Attribute Type Description name message day hour string The name of the post's author/creator. string The message or "body" of the post. This is the post's main content. int The day of the week when the post was published, in the form of an integer in the range 0-6. We will use O to represent Sunday, 1 for Monday, ... through 6 for Saturday. int The hour of the day when the post was published, in the form of an integer in the range 0-23. We will use 0 to represent midnight, 1 for 1am, ... through 23 for 11pm. The Post class must provide a constructor that takes all four values, the name, message, day, and hour, in that order. It should initialize all the fields with the corresponding parameter values. For this llab, you can assume that only valid values for the day and hour will be provided (that is, you can assume all values are in-range, and the two strings are non-null). Note on testing: since Post provides only getters, setters, and a simple constructor, there is no need to create a Post Test class for unit tests. This class serves only as data, and will be thoroughly used in testing your next class. Create a PostMonitor Class Create a new class called PostMonitor and fill in the comment details. This class represents your "monitor" that tracks information about posts. The PostMonitor class has 3 attributes. For each of the attributes below, you must: 1. Declare a field with the given name and type. 2. Define a getter method (accessor) for the field. (Again, no setter methods.) Attribute Type postCount int hourCounts array of int dayCounts array of int Description The number of posts that have been recorded. An array of 24 integers that represent the counts of the number of posts recorded for each hour of the day. An array of 7 integers that represent the counts of the number of posts recorded for each day of the week. The PostMonitor class must provide a default constructor (no parameters). It should create array objects for both array fields, and initialize the post count to zero. Create a PostMonitorTest Class Create a unit test class for your Post Monitor class. Consider giving it a field representing a single Post Monitor and initialize it in (setUp()) to a newly created instance. Add a test for your constructor. Note that when checking array values, any newly created array of integers will be automatically initialized to all zeroes. For example: int[] emptyDays = new int[7]; // array of 7 zeroes assertThat (monitor.getDayCounts()).is EqualTo(emptyDays); // check that dayCounts in 7 zeroes Methods for PostMonitor Add the folowing methods to your PostMonitor class. Write tests for each method as you go. Method recordPost() Description This method takes a single Post as a parameter. It does not return a value. It "records" seeing the post by incrementing the hour count for the hour when the post was published, and also incrementing the day count for the day when the post was published. It also increments the post count. getIndexOfLargest()) This method takes an integer array as a parameter and returns an integer representing the index (position) in the array where the largest value in the array appears. To implement this method, you can use a loop to search through the array to find the largest value. Remember to use two accumulator variables: one to remember the largest value seen so far, and one to remember the index where that value occurred. If more than one array slot contains the same largest value, return the lowest index with that value (the first one found, if searching from the beginning of the array). In your loop, be sure not to use a fixed number for the upper limit of the loop-- use the array's length, for the array that is passed in. getBusiestHour()) This method takes no parameters and returns an integer representing the hour (0-23) with the largest count. You can implement it in one line using getIndexOfLargest()). getBusiestDay()) This method takes no parameters and returns an integer representing the day (0-6) with the largest count. You can also implement this in one line. getIndexOfSmallest()) This method takes an integer array as a parameter and returns an integer representing the index (position) in the where the smallest value in the array appears. To implement this method, you can use the same techniques as for getIndexOf Largest()). If more than one array slot contains the same smallest value, return the lowest index with that value (the first one found, if searching from the beginning of the array). getSlowestHour()) getSlowestDay() This method takes no parameters and returns an integer representing the hour (0-23) with the smallest count. You can implement it in one line like before. This method takes no parameters and returns an integer representing the day (0-6) with the smallest count. You can also implement this in one line. When testing methods that work with arrays, remember you can use the following techniques: int[] hours = new int [24]; // array of 24 zeroes // Set the non-zero values you care about hours [19] = 2; hours [23] = 3; assertThat (monitor.getHourCounts()).is Equal To (hours); // Or, initialize with specific values int[] days = {0, 2, 3, 0, 0, 1, 3}; assertThat (monitor.getDayCounts()).isEqualTo(days); assertThat (monitor.getIndexOfSmallest (days)).isEqualTo(0); // Or, check individual positions in an array, if you only expect a few to matter: assertThat (hours [23]).is EqualTo(3); // Or, just type out all array values, if it is small enough: assertThat (monitor.getDayCounts()) .contains Exactly( 0, 2, 3, 0, 0, 1, 3); Create a Post Class Create a new class called Post and fill in the comment details. This class represents a single "post" or "message" on a message sharing service like Twitter or Facebook. For this lab assignment, a Post) is defined primarily by its attributes. For each of the attributes below, you must: 1. Declare a field with the given name and type. 2. Define a getter method (accessor) for the field. Note that the attributes of a Post are read-only and no setters are provided. Once the post is created, the values specified in the constructor become the "permanent" values for the fields. In this particular model, you can't go back and "edit" posts after they have been made by calling setter methods. This is a design choice for this model, but when creating your own classes on your own projects, you always have the freedom to decide whether or not a setter (or even a getter) is appropriate or not. Attribute Type Description name message day hour string The name of the post's author/creator. string The message or "body" of the post. This is the post's main content. int The day of the week when the post was published, in the form of an integer in the range 0-6. We will use O to represent Sunday, 1 for Monday, ... through 6 for Saturday. int The hour of the day when the post was published, in the form of an integer in the range 0-23. We will use 0 to represent midnight, 1 for 1am, ... through 23 for 11pm. The Post class must provide a constructor that takes all four values, the name, message, day, and hour, in that order. It should initialize all the fields with the corresponding parameter values. For this llab, you can assume that only valid values for the day and hour will be provided (that is, you can assume all values are in-range, and the two strings are non-null). Note on testing: since Post provides only getters, setters, and a simple constructor, there is no need to create a Post Test class for unit tests. This class serves only as data, and will be thoroughly used in testing your next class. Create a PostMonitor Class Create a new class called PostMonitor and fill in the comment details. This class represents your "monitor" that tracks information about posts. The PostMonitor class has 3 attributes. For each of the attributes below, you must: 1. Declare a field with the given name and type. 2. Define a getter method (accessor) for the field. (Again, no setter methods.) Create a Post Class Create a new class called Post and fill in the comment details. This class represents a single "post" or "message" on a message sharing service like Twitter or Facebook. For this lab assignment, a Post) is defined primarily by its attributes. For each of the attributes below, you must: 1. Declare a field with the given name and type. 2. Define a getter method (accessor) for the field. Note that the attributes of a Post are read-only and no setters are provided. Once the post is created, the values specified in the constructor become the "permanent" values for the fields. In this particular model, you can't go back and "edit" posts after they have been made by calling setter methods. This is a design choice for this model, but when creating your own classes on your own projects, you always have the freedom to decide whether or not a setter (or even a getter) is appropriate or not. Attribute Type Description name message day hour string The name of the post's author/creator. string The message or "body" of the post. This is the post's main content. int The day of the week when the post was published, in the form of an integer in the range 0-6. We will use O to represent Sunday, 1 for Monday, ... through 6 for Saturday. int The hour of the day when the post was published, in the form of an integer in the range 0-23. We will use 0 to represent midnight, 1 for 1am, ... through 23 for 11pm. The Post class must provide a constructor that takes all four values, the name, message, day, and hour, in that order. It should initialize all the fields with the corresponding parameter values. For this llab, you can assume that only valid values for the day and hour will be provided (that is, you can assume all values are in-range, and the two strings are non-null). Note on testing: since Post provides only getters, setters, and a simple constructor, there is no need to create a Post Test class for unit tests. This class serves only as data, and will be thoroughly used in testing your next class. Create a PostMonitor Class Create a new class called PostMonitor and fill in the comment details. This class represents your "monitor" that tracks information about posts. The PostMonitor class has 3 attributes. For each of the attributes below, you must: 1. Declare a field with the given name and type. 2. Define a getter method (accessor) for the field. (Again, no setter methods.) Create a Post Class Create a new class called Post and fill in the comment details. This class represents a single "post" or "message" on a message sharing service like Twitter or Facebook. For this lab assignment, a Post) is defined primarily by its attributes. For each of the attributes below, you must: 1. Declare a field with the given name and type. 2. Define a getter method (accessor) for the field. Note that the attributes of a Post are read-only and no setters are provided. Once the post is created, the values specified in the constructor become the "permanent" values for the fields. In this particular model, you can't go back and "edit" posts after they have been made by calling setter methods. This is a design choice for this model, but when creating your own classes on your own projects, you always have the freedom to decide whether or not a setter (or even a getter) is appropriate or not. Attribute Type Description name message day hour string The name of the post's author/creator. string The message or "body" of the post. This is the post's main content. int The day of the week when the post was published, in the form of an integer in the range 0-6. We will use O to represent Sunday, 1 for Monday, ... through 6 for Saturday. int The hour of the day when the post was published, in the form of an integer in the range 0-23. We will use 0 to represent midnight, 1 for 1am, ... through 23 for 11pm. The Post class must provide a constructor that takes all four values, the name, message, day, and hour, in that order. It should initialize all the fields with the corresponding parameter values. For this llab, you can assume that only valid values for the day and hour will be provided (that is, you can assume all values are in-range, and the two strings are non-null). Note on testing: since Post provides only getters, setters, and a simple constructor, there is no need to create a Post Test class for unit tests. This class serves only as data, and will be thoroughly used in testing your next class. Create a PostMonitor Class Create a new class called PostMonitor and fill in the comment details. This class represents your "monitor" that tracks information about posts. The PostMonitor class has 3 attributes. For each of the attributes below, you must: 1. Declare a field with the given name and type. 2. Define a getter method (accessor) for the field. (Again, no setter methods.) Attribute Type postCount int hourCounts array of int dayCounts array of int Description The number of posts that have been recorded. An array of 24 integers that represent the counts of the number of posts recorded for each hour of the day. An array of 7 integers that represent the counts of the number of posts recorded for each day of the week. The PostMonitor class must provide a default constructor (no parameters). It should create array objects for both array fields, and initialize the post count to zero. Create a PostMonitorTest Class Create a unit test class for your Post Monitor class. Consider giving it a field representing a single Post Monitor and initialize it in (setUp()) to a newly created instance. Add a test for your constructor. Note that when checking array values, any newly created array of integers will be automatically initialized to all zeroes. For example: int[] emptyDays = new int[7]; // array of 7 zeroes assertThat (monitor.getDayCounts()).is EqualTo(emptyDays); // check that dayCounts in 7 zeroes Methods for PostMonitor Add the folowing methods to your PostMonitor class. Write tests for each method as you go. Method recordPost() Description This method takes a single Post as a parameter. It does not return a value. It "records" seeing the post by incrementing the hour count for the hour when the post was published, and also incrementing the day count for the day when the post was published. It also increments the post count. getIndexOfLargest()) This method takes an integer array as a parameter and returns an integer representing the index (position) in the array where the largest value in the array appears. To implement this method, you can use a loop to search through the array to find the largest value. Remember to use two accumulator variables: one to remember the largest value seen so far, and one to remember the index where that value occurred. If more than one array slot contains the same largest value, return the lowest index with that value (the first one found, if searching from the beginning of the array). In your loop, be sure not to use a fixed number for the upper limit of the loop-- use the array's length, for the array that is passed in. getBusiestHour()) This method takes no parameters and returns an integer representing the hour (0-23) with the largest count. You can implement it in one line using getIndexOfLargest()). getBusiestDay()) This method takes no parameters and returns an integer representing the day (0-6) with the largest count. You can also implement this in one line. getIndexOfSmallest()) This method takes an integer array as a parameter and returns an integer representing the index (position) in the where the smallest value in the array appears. To implement this method, you can use the same techniques as for getIndexOf Largest()). If more than one array slot contains the same smallest value, return the lowest index with that value (the first one found, if searching from the beginning of the array). Attribute Type postCount int hourCounts array of int dayCounts array of int Description The number of posts that have been recorded. An array of 24 integers that represent the counts of the number of posts recorded for each hour of the day. An array of 7 integers that represent the counts of the number of posts recorded for each day of the week. The PostMonitor class must provide a default constructor (no parameters). It should create array objects for both array fields, and initialize the post count to zero. Create a PostMonitorTest Class Create a unit test class for your Post Monitor class. Consider giving it a field representing a single Post Monitor and initialize it in (setUp()) to a newly created instance. Add a test for your constructor. Note that when checking array values, any newly created array of integers will be automatically initialized to all zeroes. For example: int[] emptyDays = new int[7]; // array of 7 zeroes assertThat (monitor.getDayCounts()).is EqualTo(emptyDays); // check that dayCounts in 7 zeroes Methods for PostMonitor Add the folowing methods to your PostMonitor class. Write tests for each method as you go. Method recordPost() Description This method takes a single Post as a parameter. It does not return a value. It "records" seeing the post by incrementing the hour count for the hour when the post was published, and also incrementing the day count for the day when the post was published. It also increments the post count. getIndexOfLargest()) This method takes an integer array as a parameter and returns an integer representing the index (position) in the array where the largest value in the array appears. To implement this method, you can use a loop to search through the array to find the largest value. Remember to use two accumulator variables: one to remember the largest value seen so far, and one to remember the index where that value occurred. If more than one array slot contains the same largest value, return the lowest index with that value (the first one found, if searching from the beginning of the array). In your loop, be sure not to use a fixed number for the upper limit of the loop-- use the array's length, for the array that is passed in. getBusiestHour()) This method takes no parameters and returns an integer representing the hour (0-23) with the largest count. You can implement it in one line using getIndexOfLargest()). getBusiestDay()) This method takes no parameters and returns an integer representing the day (0-6) with the largest count. You can also implement this in one line. getIndexOfSmallest()) This method takes an integer array as a parameter and returns an integer representing the index (position) in the where the smallest value in the array appears. To implement this method, you can use the same techniques as for getIndexOf Largest()). If more than one array slot contains the same smallest value, return the lowest index with that value (the first one found, if searching from the beginning of the array). Attribute Type postCount int hourCounts array of int dayCounts array of int Description The number of posts that have been recorded. An array of 24 integers that represent the counts of the number of posts recorded for each hour of the day. An array of 7 integers that represent the counts of the number of posts recorded for each day of the week. The PostMonitor class must provide a default constructor (no parameters). It should create array objects for both array fields, and initialize the post count to zero. Create a PostMonitorTest Class Create a unit test class for your Post Monitor class. Consider giving it a field representing a single Post Monitor and initialize it in (setUp()) to a newly created instance. Add a test for your constructor. Note that when checking array values, any newly created array of integers will be automatically initialized to all zeroes. For example: int[] emptyDays = new int[7]; // array of 7 zeroes assertThat (monitor.getDayCounts()).is EqualTo(emptyDays); // check that dayCounts in 7 zeroes Methods for PostMonitor Add the folowing methods to your PostMonitor class. Write tests for each method as you go. Method recordPost() Description This method takes a single Post as a parameter. It does not return a value. It "records" seeing the post by incrementing the hour count for the hour when the post was published, and also incrementing the day count for the day when the post was published. It also increments the post count. getIndexOfLargest()) This method takes an integer array as a parameter and returns an integer representing the index (position) in the array where the largest value in the array appears. To implement this method, you can use a loop to search through the array to find the largest value. Remember to use two accumulator variables: one to remember the largest value seen so far, and one to remember the index where that value occurred. If more than one array slot contains the same largest value, return the lowest index with that value (the first one found, if searching from the beginning of the array). In your loop, be sure not to use a fixed number for the upper limit of the loop-- use the array's length, for the array that is passed in. getBusiestHour()) This method takes no parameters and returns an integer representing the hour (0-23) with the largest count. You can implement it in one line using getIndexOfLargest()). getBusiestDay()) This method takes no parameters and returns an integer representing the day (0-6) with the largest count. You can also implement this in one line. getIndexOfSmallest()) This method takes an integer array as a parameter and returns an integer representing the index (position) in the where the smallest value in the array appears. To implement this method, you can use the same techniques as for getIndexOf Largest()). If more than one array slot contains the same smallest value, return the lowest index with that value (the first one found, if searching from the beginning of the array). getSlowestHour()) getSlowestDay() This method takes no parameters and returns an integer representing the hour (0-23) with the smallest count. You can implement it in one line like before. This method takes no parameters and returns an integer representing the day (0-6) with the smallest count. You can also implement this in one line. When testing methods that work with arrays, remember you can use the following techniques: int[] hours = new int [24]; // array of 24 zeroes // Set the non-zero values you care about hours [19] = 2; hours [23] = 3; assertThat (monitor.getHourCounts()).is Equal To (hours); // Or, initialize with specific values int[] days = {0, 2, 3, 0, 0, 1, 3}; assertThat (monitor.getDayCounts()).isEqualTo(days); assertThat (monitor.getIndexOfSmallest (days)).isEqualTo(0); // Or, check individual positions in an array, if you only expect a few to matter: assertThat (hours [23]).is EqualTo(3); // Or, just type out all array values, if it is small enough: assertThat (monitor.getDayCounts()) .contains Exactly( 0, 2, 3, 0, 0, 1, 3); getSlowestHour()) getSlowestDay() This method takes no parameters and returns an integer representing the hour (0-23) with the smallest count. You can implement it in one line like before. This method takes no parameters and returns an integer representing the day (0-6) with the smallest count. You can also implement this in one line. When testing methods that work with arrays, remember you can use the following techniques: int[] hours = new int [24]; // array of 24 zeroes // Set the non-zero values you care about hours [19] = 2; hours [23] = 3; assertThat (monitor.getHourCounts()).is Equal To (hours); // Or, initialize with specific values int[] days = {0, 2, 3, 0, 0, 1, 3}; assertThat (monitor.getDayCounts()).isEqualTo(days); assertThat (monitor.getIndexOfSmallest (days)).isEqualTo(0); // Or, check individual positions in an array, if you only expect a few to matter: assertThat (hours [23]).is EqualTo(3); // Or, just type out all array values, if it is small enough: assertThat (monitor.getDayCounts()) .contains Exactly( 0, 2, 3, 0, 0, 1, 3); getSlowestHour()) getSlowestDay() This method takes no parameters and returns an integer representing the hour (0-23) with the smallest count. You can implement it in one line like before. This method takes no parameters and returns an integer representing the day (0-6) with the smallest count. You can also implement this in one line. When testing methods that work with arrays, remember you can use the following techniques: int[] hours = new int [24]; // array of 24 zeroes // Set the non-zero values you care about hours [19] = 2; hours [23] = 3; assertThat (monitor.getHourCounts()).is Equal To (hours); // Or, initialize with specific values int[] days = {0, 2, 3, 0, 0, 1, 3}; assertThat (monitor.getDayCounts()).isEqualTo(days); assertThat (monitor.getIndexOfSmallest (days)).isEqualTo(0); // Or, check individual positions in an array, if you only expect a few to matter: assertThat (hours [23]).is EqualTo(3); // Or, just type out all array values, if it is small enough: assertThat (monitor.getDayCounts()) .contains Exactly( 0, 2, 3, 0, 0, 1, 3);
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
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...
-
Different theories about early childhood inform approaches to children's learning and development. Early childhood educators draw upon a range of perspectives in their work ..." (EYLF p.12)....
-
How fast does a 200-Hz sound wave with a wavelength of 1.7 m travel?
-
Journalize, record, and post when appropriate the following transactions into the sales journal (same headings as exercise E13-1A) and general journal (page 1). All sales carry terms of 2/10, n/30....
-
The wreck of the S.S. Central America waited 130 years at the bottom of the ocean for someone to come along and claim its trove of gold. Thomas G. Thompson, funded by a multitude of investors, was...
-
Outdoor Athletic Equipment Co. operates two divisionsthe Winter Sports Division and the Summer Sports Division. The following income and expense accounts were provided from the trial balance as of...
-
At some point in the life of a company or firm, a decision of how to expand is necessary. This is especially important in for-profit firms as shareholders typically require larger and larger...
-
The file Problem5_9.xlsx contains passing statistics for NFL teams during the 2017 season. Using formulas that do combine INDEX and MATCH in the same cell, return the desired statistics in the range...
-
10 46 points eBook References You estimate that you can save $3,000 by selling your home yourself rather than using a real estate agent. What would be the future value of that amount if invested for...
-
Suppose the stock in question 2 pays a dividend of $0.225/share per quarter. You expect the dividend to be paid 3, 6, 9, and 12 months into the life of the forward. The appropriate risk-free rate for...
-
a) c) Solve the following utility maximization problem max 3 X1 X 2x + x = 8 0,4 0,6 max X X 11--2 (x + 2) 3x + 4x = 5 b) d) max_x + xx + X +1 x + 3x = 9 max (x + 1)(x +2) x1+x Px + Px = I P, P,1 > 0.
-
You just won the lottery. The prize is 20 equal payments of $50,000 with the first to be received today. What is the present value of the prize if the discount rate is 8%?
-
A bond with face value of $1,000 mature in 12 years. The bond has 8 percent annual coupon. If YTM remains at 6.0 percent, what will be the price of the bond two years from today?
-
Solve the heat equation modeling the heat conduction inside of a metal rod of length L, which is perfectly insulated on all sides, including the ends, so that it satisfies the homogeneous Neumann...
-
Among the factors to consider below, which is the best combination to determine if the project is justifiable? A. Payback period alone will suffice. B. Payback Period and AW C. IRR and D. ERR and...
-
As economic conditions change, how do banks adjust their asset portfolio?
-
Describe four generational cohorts.
-
Goldberg and Heath met while working at a media company and they quickly learned that they shared a passion for entrepreneurship. We shared a lot of ideas about businesses that we thought were...
-
What is the purpose of loss-leader pricing when used by a retail firm?
-
V. Zarb, the marketing manager for Maltese Treasures Ltd, is preparing a sales budget for the year ended 30 June 2020. In reviewing the actual sales data for the previous year, the sales and...
-
The following expenses budget has been prepared for Abacus Services for the year ending 30 June 2020. Professional salaries, secretarial wages and training are paid in the quarter in which they are...
-
Bounce Athletics Ltd, which develops and runs athletics training programs for primary schools, has budgeted revenue for the first 6 months of 2020 as follows. All revenue is provided on account and...
Study smarter with the SolutionInn App