1- Use FirstLastList: Write method public void
join(FirstLastList SecondList) such that given two
linked lists, join them together to give one. So if the lists lst1=
[1,3,7,4] and lst2=[2,4,5,8,6], the result of lst1.join(lst2) is
lst1=[1,3,7,4,2,4,5,8,6] and lst2=[].
2- Use FirstLastList: Write method public void
swap(). It swaps the first and last elements of a
FirstLastList. So if lst1= [1,3,7,4], lst1.swap() = [4,3,7,1].
Display or throw an exception if the list contains less than two
elements.
Demonstrate by displaying the list contents before
and after calling the above methods. Eg:
lst1
[1,3,7,4]
lst2
[2,4,5,8,6]
lst1.join(lst2)
[1,3,7,4,2,4,5,8,6]
lst1.swap()
[6,3,7,4,2,4,5,8,1]
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// firstLastList.java
// demonstrates list with first and last references
// to run this program: C>java FirstLastApp
////////////////////////////////////////////////////////////////
class Link
{
public long dData; // data item
public Link next; // next link in list
//
-------------------------------------------------------------
public Link(long d) // constructor
{ dData = d; }
//
-------------------------------------------------------------
public void displayLink() // display this link
{ System.out.print(dData + " "); }
//
-------------------------------------------------------------
} // end class Link
////////////////////////////////////////////////////////////////
class FirstLastList
{
private Link first; // ref to first link
private Link last; // ref to last link
//
-------------------------------------------------------------
public FirstLastList() // constructor
{
first = null; // no links on list yet
last = null;
}
//
-------------------------------------------------------------
public boolean isEmpty() // true if no links
{ return first==null; }
//
-------------------------------------------------------------
public void insertFirst(long dd) // insert at front of list
{
Link newLink = new Link(dd); // make new link
if( isEmpty() ) // if empty list,
last = newLink; // newLink <-- last
newLink.next = first; // newLink --> old first
first = newLink; // first --> newLink
}
//
-------------------------------------------------------------
public void insertLast(long dd) // insert at end of list
{
Link newLink = new Link(dd); // make new link
if( isEmpty() ) // if empty list,
first = newLink; // first --> newLink
else
last.next = newLink; // old last --> newLink
last = newLink; // newLink <-- last
}
//
-------------------------------------------------------------
public long deleteFirst() // delete first link
{ // (assumes non-empty list)
long temp = first.dData;
if(first.next == null) // if only one item
last = null; // null <-- last
first = first.next; // first --> old next
return temp;
}
//
-------------------------------------------------------------
public void displayList()
{
System.out.print("List (first-->last): ");
Link current = first; // start at beginning
while(current != null) // until end of list,
{
current.displayLink(); // print data
current = current.next; // move to next link
}
System.out.println("");
}
//
-------------------------------------------------------------
} // end class FirstLastList
////////////////////////////////////////////////////////////////
class FirstLastApp
{
public static void main(String[] args)
{ // make a new list
FirstLastList theList = new FirstLastList();
theList.insertFirst(22); // insert at front
theList.insertFirst(44);
theList.insertFirst(66);
theList.insertLast(11); // insert at rear
theList.insertLast(33);
theList.insertLast(55);
theList.displayList(); // display the list
theList.deleteFirst(); // delete first two items
theList.deleteFirst();
theList.displayList(); // display again
} // end main()
} // end class FirstLastApp
////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Class FirstLastAppTest.Java is only for testing. Please do not Edit.
class FirstLastAppTest
{
public static void main(String[] args)
{
FirstLastList lst1 = new FirstLastList(); // Start a new FirstLastList called lst1
lst1.insertLast(1); // Add links with data to the last position
lst1.insertLast(3);
lst1.insertLast(7);
lst1.insertLast(4);
System.out.print("\nlst1: "); // print the description for the list
lst1.displayList(); // print the contents of the list
FirstLastList lst2 = new FirstLastList(); // Start a new FirstLastList called lst2
lst2.insertLast(2); // Add links with data to the last position
lst2.insertLast(4);
lst2.insertLast(5);
lst2.insertLast(8);
lst2.insertLast(6);
System.out.print("\nlst2: "); // print the description for the list
lst2.displayList(); // print the contents of the list
System.out.print("\nlst1.join(lst2): "); // print the action to take place: lst1.join(lst2)
lst1.join(lst2); // call the join method for lst1 to add lst2
System.out.print("\nlst1: "); // print the description for the list
lst1.displayList(); // print the contents of the list lst1; post join()
System.out.print("lst2: "); // print the description for the list
lst2.displayList(); // print the contents of the list lst2; post join()
System.out.print("\nlst1.swap(): "); // print the action to take place: lst1.swap()
lst1.swap(); // call the swap method for lst1
System.out.print("\nlst1: "); // print the description for the list
lst1.displayList(); // print the contents of the list lst1; post swap()
} // end main()
} // end class In: Computer Science
Binomial Distribution
Tom and Jerry play one game per day. It is known that Tom’s winning chance is P[W] = 0.6 and if he does not win, then he loses. Game results are assumed to be independent. After FOUR days, variable T indicates a total number of games won by Tom. So J = 4 − T is the number of games he lost (or Jerry won).
Use the formula for binomial probabilities and probability rules to answer questions below.
Find the chance that Tom loses exactly one game,
P (J = 1)
Evaluate probability that Tom wins at least two games,
P [T ≥ 2]
Determine the chance than Jerry wins two or more games,
P [J ≥ 2]
Find expected number of games won by Tom,
E[T]
Use the formula for variance to determine the variance of T, that is
Var[T]
Assume that after a game is over, the winner gets $1 from his
partner. Thus the variable of interest is the balance for Tom,
which is B = T − J. Evaluate the expected balance,
E[B]
7. Derive the variance of B, that is Var[B]
In: Statistics and Probability
In: Statistics and Probability
| Calories |
| 70 |
| 120 |
| 70 |
| 50 |
| 110 |
| 110 |
| 110 |
| 130 |
| 90 |
| 90 |
| 120 |
| 110 |
| 120 |
| 110 |
| 110 |
| 110 |
| 100 |
| 110 |
| 110 |
| 110 |
| 100 |
| 110 |
| 100 |
| 100 |
| 110 |
| 110 |
| 100 |
| 120 |
| 120 |
| 120 |
| 110 |
| 110 |
| 140 |
| 110 |
| 160 |
| 140 |
| 130 |
| 120 |
| 50 |
| 50 |
In: Statistics and Probability
Specialty Auto Insurance wishes to compare the repair costs of moderatly damaged cars at two repair shops. To do this they sent seven cars to both repair shops to get the repair costs. The data is shown below. At the 0.01 significance level, can we conclude if there is a difference in the average repair costs for the two repair shops? Show your hypotheses. Explain your findings in a text box to the right.
| Car | Repair Shop 1 | Repair Shop 2 |
| 1 | $7,100 | $7,900 |
| 2 | $9,000 | $10,100 |
| 3 | $11,000 | $12,200 |
| 4 | $8,900 | $8,800 |
| 5 | $9,900 | $10,400 |
| 6 | $9,100 | $9,800 |
| 7 | $10,300 | $11,700 |
In: Statistics and Probability
Write a C++ program that does the following:
Read and input file containing the following
PersonAName, PersonBName, XA,YA, XB, YB
where the coordinates of PersonA in a 100 by 100 room is XA, YA
and the coordinates of PersonB is XB, YB.
Use square root function in cmath sqrt() to calculate the shortest distance between two points.
A file will be uploaded in this assignment that will list coordinates of two people.
The program should use a function call that returns the distance. If the distance is less than 6 feet, the report the case giving the names and the calculated distance.
Blackboard will be updated with a data file by Saturday morning.
Data fields
Person A Name Column 1-10
Person B Name Column 11-20
Person A X coordinate 21-23
Person A Y coordinate 25-27
Person B X coordinate 31-33
Person B Y coordinate 35-37
Attached file coordinates.txt
1---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 Apple John 5 2 3 4 Apple Ben 5 2 10 4 Apple Carla 5 2 4 3 Apple Sonny 5 2 70 55 Tom Jerry 24 34 29 39 Tom Tim 24 34 50 55 Tom Tracy 24 34 88 31 Tom Tammy 24 34 87 90 Jim Tammy 74 89 87 90 James Tammy 72 88 87 90 Josh Tammy 59 24 87 90 Barry Tom 12 78 13 65 Barry Carla 12 78 4 3 Barry John 12 78 3 4 Barry Sonny 12 78 70 55 Barry Jerry 12 78 29 39 Barry Juan 12 78 14 80 Ann Margaret 25 44 28 79 Ann Silvia 25 44 25 55
In: Computer Science
A newspaper story headline reads "Gender Plays Part in Monkeys' Toy Choices, Research Finds—Like Humans, Male Monkeys Choose Balls and Cars, While Females Prefer Dolls and Pots."† The article goes on to summarize findings published in the paper "Sex Differences in Response to Children's Toys in Nonhuman Primates."† Forty-four male monkeys and 44 female monkeys were each given a variety of toys, and the time spent playing with each toy was recorded. The table gives means and standard deviations (approximate values read from graphs in the paper) for the percentage of the time that a monkey spent playing with a particular toy. Assume that it is reasonable to regard these two samples of 44 monkeys as representative of the populations of male monkeys and of female monkeys. Use a 0.05 significance level for any hypothesis tests that you carry out when answering the various parts of this exercise. (Use μ1 for male monkeys and μ2 for female monkeys.)
| Percent of Time | |||||||
|---|---|---|---|---|---|---|---|
| Female Monkeys | Male Monkeys | ||||||
| n | Sample Mean |
Sample Standard Deviation |
n | Sample Mean |
Sample Standard Deviation |
||
| Toy | Police Car | 44 | 7 | 4 | 44 | 19 | 6 |
| Doll | 44 | 19 | 4 | 44 | 10 | 2 | |
| Furry Dog | 44 | 20 | 5 | 44 | 26 | 5 | |
(a)
The police car was considered a "masculine" toy. Do these data provide convincing evidence that the mean percentage of the time spent playing with the police car is greater for male monkeys than for female monkeys?
State the appropriate null and alternative hypotheses.
Find the test statistic and P-value. (Use technology. Round your test statistic to one decimal place and your P-value to three decimal places.)
State the conclusion in the problem context.
(b)
The doll was considered a "feminine" toy. Do these data provide convincing evidence that the mean percentage of the time spent playing with the doll is greater for female monkeys than for male monkeys?
State the appropriate null and alternative hypotheses.
Find the test statistic and P-value. (Use technology. Round your test statistic to one decimal place and your P-value to three decimal places.)
State the conclusion in the problem context.
(c)
The furry dog was considered a "neutral" toy. Do these data provide convincing evidence that the mean percentage of the time spent playing with the furry dog is not the same for male and female monkeys?
State the appropriate null and alternative hypotheses.
Find the test statistic and P-value. (Use technology. Round your test statistic to one decimal place and your P-value to three decimal places.)
State the conclusion in the problem context.
In: Statistics and Probability
What college basketball conferences have the higher probability of having a team play in college basketball's national championship game? Over the last 20 years, Conference A ranks first by having a team in the championship game 11 times. Conference B ranks second by having a team in the championship game 8 times. However, these two conferences have both had teams in the championship game only one time. Use these data to estimate the following probabilities.
(a)
What is the probability that Conference A will have a team in the championship game?
(b)
What is the probability that Conference B will have a team in the championship game?
(c)
What is the probability that Conference A and Conference B will both have teams in the championship game?
(d)
What is the probability at least one team from these two conferences will be in the championship game? That is, what is the probability a team from Conference A or Conference B will play in the championship game?
(e)
What is the probability that the championship game will not a have team from one of these two conferences?
In: Statistics and Probability
Liam is a 17-year-old male who is being seen by his family physician for his annual physical examination. Liam’s sexual maturation rating is estimated to be 3. He weighs 114 lbs and stands 5’6” tall.
When he was 16 y.o., his height was 5’5” and weight was 106 lbs.
At 15 y.o., Liam was 5’3” tall and weighed 98lbs.
During the visit, Liam reports that he has been experimenting with a vegan diet since his visit last year. He explains that he thinks it is a healthier way to eat and states that he avoids milk, beef, and pork eats poultry or fish once every two weeks and eats cheese 3-4x/wk. Breakfast is usually cold cereal with almond milk because he heard that was a healthy milk alternative. He likes pasta, pizza, and salad, which he eats almost every day.
For exercise, he runs 3 miles 2x/wk, plays basketball with friends after school 3x/wk for an hour, and lifts weights in his garage for 45 min 5x/wk.
He says he would like to gain muscle and grow taller.
3. What clarifying questions would you like to ask Liam about his current behaviors? List 3.
4. If there is protein a concern in Liam’s diet, why? Estimate his RDA and use evidence to support your position.
5. Given Liam’s diet and exercise patterns, which dietary components may he be deficient in? For each dietary component, list possible food sources that are appropriate for his current eating pattern.
6. There are both health benefits and costs of eating mostly plants. How might his current way of eating affect Liam’s growth and maturation?
7. Is it necessary to assess Liam for the presence of an eating disorder? Provide support for your answer.
In: Nursing
The given stemplot shows the percentages of adults aged 18–34 who were considered minorities in each of the states and the District of Columbia.
| 0 | 8 8 9 |
| 1 | 1 5 5 6 7 8 9 |
| 2 | 0 2 2 3 3 3 3 3 3 6 7 7 8 |
| 3 | 0 1 1 1 4 5 7 9 9 |
| 4 | 0 1 1 1 2 5 8 8 |
| 5 | 1 1 1 2 2 3 4 |
| 6 | 1 7 7 |
| 7 | 5 |
(a) Make another stemplot of this data by splitting the stems, placing leaves 00 to 44 on the first stem and leaves 55 to 99 on the second stem of the same value.
(b) Create a histogram that uses class intervals that give the same pattern as the stemplot you created with the split stems. It might be a good idea to do this by hand. If you use software, you may have to adjust the settings in order to get a histogram that matches the stemplot exactly.
In: Statistics and Probability