Making Rectangle comparator an inner class
3.5. A very specialized class, such as the RectangleComparator, can be defined inside the method that uses it.
Reorganize your program so that the RectangleComparator class is defined inside the main method of your test class.
What is your main method now?
Your answer :
4. There are at least two good reasons why you might choose to build a class as an inner class inside of another containing class:
1) The inner class will never be used to instantiate objects outside of the containing class, so we are effectively hiding the inner class from other classes.
2) The inner class needs access to data that is defined inside the containing class. In this case, the inner class is positioned in the scope of the shared variables of the containing class. As a result the containing class variables don’t need to be passed to the inner class. This is particularly handy if lots of information must be shared, as is often the case for listener classes in a graphics application.
There is one good reason not to build inner classes: Inner classes break the object-oriented notion of “data hiding” – the idea that class variables are private and are only accessible by public accessor and mutator methods in the same class. When we build inner classes we should remember that we are breaking an important object-oriented design principle and we should have a compelling reason to design in this way.
In this problem we will gain some experience working with inner classes. The Person class below contains an inner class called Memory in which we can store String objects that represent events in the life of a Person object. We have decided that class Memory will never be used outside of Person and that the Person class contains data that is needed by the Memory class. Here is the code.
import java.util.*;
public class Person
{
private String name;
private int age;
private Memory mem;
public Person(String name, int age)
{
this.name = name;
this.age = age;
mem = new Memory();
}
public String toString()
{
return "Name: " + name + '\n' +
"Age: " + age + '\n';
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public void tellAll()
{
mem.dumpMemory();
}
public void rememberAnEvent(String s)
{
mem.addLifeData(s);
}
// Start of inner class Memory
private class Memory
{
ArrayList<String> lifeData;
private Memory()
{
lifeData = new ArrayList<String>();
lifeData.add("Name: " + name);
lifeData.add("Age: " + age);
}
public void addLifeData(String datum)
{
lifeData.add(datum);
}
public void dumpMemory()
{
for (String s: lifeData)
{
System.out.println(s);
}
}
}
}
Here is a driver for the Person class.
public class PersonRunner
{
public static void main(String[] args)
{
Person aperson = new Person("Bob", 33);
aperson.tellAll();
aperson.rememberAnEvent("I was born in 1970.");
aperson.rememberAnEvent("I finished school in 2003.");
aperson.tellAll();
}
}
Notice that the private data in Person includes instance variables name and age. Look inside the inner class Memory and notice that name and age are referenced directly in the Memory constructor without invoking an accessor method. This is only possible because the Memory constructor is in the scope of name and age.
In order to understand the effects of an inner class, remove class Memory from Person and make it a standalone class. Make all the changes that are needed in each class to make the new design work.
Your answer :
import java.util.Comparator;
import java.awt.Rectangle;
public class RectangleComparator implements Comparator<Rectangle>
{
/**
Compares two Rectangle objects.
@param r1 the first rectangle
@param r2 the second rectangle
@return 1 if the area of the first rectangle is larger than the area of
the second rectangle, -1 if the area of the first rectangle is
smaller than the area of the second rectangle or 0 if the two
rectangles have the same area
*/
public int compare(Rectangle r1, Rectangle r2)
{
. . .
}
}
In: Computer Science
Write an interoffice memo notifying staff that new insurance coverage will take effect at the beginning of next month. Representatives from Prudential, the new company, will be in Conference Room A to provide information and to answer any questions regarding the new policy. Remember to include the time and date.
In: Operations Management
A new soft drink is being market tested. It is estimated that 60% of consumers will like
the new drink. A sample of 96 taste-tested the new drink.
(a) Determine the standard error of the proportion.
(b) What is the probability that more than 70% of consumers will indicate they like the drink?
In: Statistics and Probability
Suppose a linked list of 20 nodes. The middle node has a data –250. Write the pseudocode to replace the middle node of the linked list with a new node and new data. Assume that the list's head pointer is called head_ptr and the data for the new node is called entry
In: Computer Science
Suppose a linked list of 20 nodes. The middle node has a data –250. Write the pseudocode to replace the middle node of the linked list with a new node and new data. Assume that the list's head pointer is called head_ptr and the data for the new node is called entry
In: Computer Science
6) Which chamber of the peniss fills with very little blood during the erection process? Why doesn’t this section fill as much as the other chambers? (2 points)
7) Select all of the following that are functions of the accessory glands of the male reproductive system. (2 points)
A) Spermatocyte creation
B) Supplying nutrients for gamete motility
C) Moving fluids along the reproductive tract
D) Buffer production
E) Hormone secretion for fertility regulation
8) Which of the following could be issues caused by dysfunctional interstitial cells of the testes in an adult male? Select all that apply. (2 points)
A) Low sperm cell production
B) Increased levels of GnRH in the blood
C) No formation of the male reproductive structures
D) A lack of growth plate ossification
E) Lower energy levels in the body
9) Regular steroid injections of testosterone would cause which of the following to occur? (1 point)
A) Decreased sex drive
B) Decreased levels of GnRH
C) Increased levels of LH and FSH
D) All of the answers are correct.
E) None of the answers is correct.
10) Select all of the following that will result from a vasectomy procedure. (1 point)
A) Sterility
B) Lack of ejaculation
C) Increased muscle mass
D) A surge in testosterone production
E) Decreased erection capabilities
11) Which of the following statements concerning oogenesis is true? (1 point)
A) Oogenesis begins after birth
B) Ova develop from stem cells called oogenesis
C) An ovum completes its last mitosis after it is fertilized
D) About half the oogonia complete mitosis between birth and puberty
E) By the time of their birth, girls have already lost about 80 percent of their oocytes
12) Select all of the following that are true of the vagina. (1 point)
A) Loses its inner lining during menses
B) Has a cervix for connection to the uterus
C) Holds sperm before their movement to the uterus
D) Is the lower region of the birth canal
E) Assists in urine movement via the urethra
In: Anatomy and Physiology
Cognitive-based therapy (CBT) and family-based therapy (FBT) are two different treatments for anorexia. In an experimental study, forty-six anorexic teenage girls were randomly assigned to two groups. One group, consisting of n1 = 29 individuals, received CBT, and the other group, consisting of n2 = 17 individuals, received FBT. Weight of each individual is measured twice, once at the beginning and once at the end of the study period. The variable of interest is the weight change, i.e. weight after therapy minus weight before therapy. The data collected from the two samples are given below.
cognitive = c(1.7, 0.7, -0.1, -0.7, -3.5, 14.9, 3.5, 17.1, -7.6, 1.6, 11.7, 6.1,
1.1, -4.0, 20.9, -9.1, 2.1, -1.4, 1.4, -0.3, -3.7, -0.8, 2.4, 12.6, 1.9, 3.9,
0.1, 15.4, -0.7)
family = c(11.4, 11.0, 5.5, 9.4, 13.6, -2.9, -0.1, 7.4, 21.5, -5.3, -3.8, 13.4,
13.1, 9.0, 3.9, 5.7, 10.7)
Note that a positive weight change (weight gain) is generally good for anorexia patients. Let μ1 be the population mean weight change in the CBT group, and μ2 the population mean weight change in the FBT group. The goal is to conduct statistical inference on the difference μ1 − μ2
-
4. Two-sample t-test relies on the assumption that the two samples are either large enough (n1 ≥ 30 and n2 ≥ 30) or coming from normal distributions. In the context of this problem, neither of the two samples is large enough.
(a) Check the normality assumption for both samples using the normal quantile-quantile plot. Re- member that you can do this in R using the qqnorm command.
(b) Suppose one thinks that the normality assumption does not hold for this data set, hence does not trust the results provided in the two-sample t-test. Suggest a different hypothesis testing procedure that does not rely on the normality assumption. (Note: You don’t have to carry out the test.
In: Math
Merchandising has come a long way from the days when “marks” were carved on silver goblets or earthenware jugs to identify the wares produced by a certain silversmith or potter. Their traditional role was to create a link in the prospective buyer’s mind between the product and the producer. The power of attraction of trade-marks and other “famous brand names” is now recognized as among the most valuable of business assets. However, whatever their commercial evolution, the legal purpose of trade-marks continues (in terms of s. 2 of the Trade-marks Act, R.S.C. 1985, c. T-13 ) to be their use by the owner “to distinguish wares or services manufactured, sold, leased, hired or performed by him from those manufactured, sold, leased, hired or performed by others”. It is a guarantee of origin and inferentially, an assurance to the consumer that the quality will be what he or she has come to associate with a particular trade-mark (as in the case of the mythical “Maytag” repairman).
The BARBIE doll is said by the manufacturer, Mattel Inc. to be
an iconic figure of pop culture. And so, within limits, it is. The
sale of various BARBIE products annually exceeds $1.4 billion
worldwide, representing 35 percent of the appellant’s sales. The
appellant advises that Canadian girls aged 3 to 11 years are given
an average of two BARBIE dolls per year. Mattel was recently
advised that a company is seeking to register trade-marks in
connection with its small chain of Montreal suburban “Barbie’s”
restaurants. Mattel feels the use of the name (albeit in relation
to different wares and services) would likely create confusion in
the marketplace. On a casual acquaintance with both marks, it is
contended, there is a likelihood that consumers would think that
the doll people had something to do with a restaurant called
“Barbie’s”. Or, as Mattel framed its point in a consumer survey by
asking the following question “Do you believe that the company that
makes Barbie dolls might have anything to do with the restaurant
identified by this sign or logo?” (Emphasis added.)
Question:
The matter proceeds to Court. How do you think a court would
rule on the issue and why?
**Please do not copy previous answers. Thank you.
In: Operations Management
Matwirth corporation has instituted a new disciplinary policy for employees who fail a random drug test. The personnel office wishes to test to see if there is a difference in employee behavior based on the new policy. The records of 500 employee drug tests from before the new policy were randomly selected and 500 drug test results from after the new policy were also randomly selected. In the sample from before the new policy, 1.80% tested positive, while 1.40% in the sample from after the new policy tested positive.
For the hypotheses,
H0: p1 = p2 and HA: p1 > p2,
what is the p-value and the conclusion of this test at the 0.1 level of significance?
8. Construct a 99% confidence interval for the population mean for a sample of size 20 with mean 5.01 and standard deviation 2.21.
WITH EXPLAINATION OF WORK
In: Statistics and Probability
Janet is running a painting business. She receives $200,000 payment from buyers at the end of year, at which time she also pays $20,000 fixed cost and 30% of the revenues as a variable cost.
1.An opportunity for new business opens for Janet from which she will make $100,000 accounting profits at the end of year. If she takes this new business, then she has to reduce her work for painting business, so the revenue from painting business will drop by 30%. What will be the size of annual economic profit from the new business?
2.If the new business will last only for the next five years, so she can take the profits from the new business for five times starting from one year from now, what is the size of the value of the new business for Janet? Assume that the annual interest rate is 5%.
In: Finance