Use the following data set that compares age to average "years left to live" to answer the following questions.
Age 10 20 30 40 50 60 70 80 90 100
Years to live 59.2 49.6 40.7 31.9 24.0 17.2 11.6 7.2 4 .4 2.8
a) Show the scatterplot for this data with the least squares regression line. Find R^2. How much of the variation is explained by the regression line?
b) Experiment with the non-linear regressions available on the calculator. Which seem to fit? Show the scatterplot with three different regression curves from the calculator. Label each equation, as well as the applicable R^2.
c) Choose a regression equation to predict how many "years left" a person has if he is now 101 years old. Can he count on celebrating Christmas 2015?
InfoTest.javaInfoTest.javapackage assignment1;
importstatic org.junit.Assert.*;
import org.junit.Test;
publicclassInfoTest{
@Test
publicvoid testInfo(){
Info tempInfo =newInfo();
assertNotNull(tempInfo.tmp);
}
@Test
publicvoid testInsert(){
Info tempInfo =newInfo();
// Insert into an empty list
tempInfo.insert(30);
assertEquals(30, tempInfo.get(0));
// Insert an item to be placed at the beginning of the list
tempInfo.insert(4);
assertEquals(4, tempInfo.get(0));
assertEquals(30, tempInfo.get(1));
// Insert an item to be placed at the end of the list
tempInfo.insert(20);
assertEquals(20, tempInfo.get(1));
assertEquals(30, tempInfo.get(2));
// Insert an which already exists
tempInfo.insert(20);
assertEquals(4, tempInfo.get(0));
assertEquals(20, tempInfo.get(1));
assertEquals(30, tempInfo.get(2));
}
@Test
publicvoid testDelete(){
Info tempInfo =newInfo();
tempInfo.insert(15);
tempInfo.insert(5);
tempInfo.insert(10);
// delete from the middle
tempInfo.delete(10);
assertEquals(5, tempInfo.get(0));
assertEquals(15, tempInfo.get(1));
// delete from the beginning
tempInfo.insert(10);
tempInfo.delete(5);
assertEquals(10, tempInfo.get(0));
assertEquals(15, tempInfo.get(1));
// delete from the end
tempInfo.insert(5);
tempInfo.delete(15);
assertEquals(5, tempInfo.get(0));
assertEquals(10, tempInfo.get(1));
// delete something that does not exist
tempInfo.insert(15);
tempInfo.delete(7);
assertEquals(5, tempInfo.get(0));
assertEquals(10, tempInfo.get(1));
assertEquals(15, tempInfo.get(1));
}
@Test
publicvoid testGet(){
Info tempInfo =newInfo();
tempInfo.insert(15);
tempInfo.insert(5);
tempInfo.insert(10);
// get items at the beginning, middle, and end of the list
assertEquals(5, tempInfo.get(0));
assertEquals(10, tempInfo.get(1));
assertEquals(15, tempInfo.get(2));
// get an unexisting item
assertNull(tempInfo.get(3));
}
@Test
publicvoid testCount(){
Info tempInfo =newInfo();
/ ...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Use the following data set that compares age to average years lef.docx
1. Use the following data set that compares age to average "years
left to live" to answer the following questions.
Age 10 20 30 40 50 60 70 80 90 100
Years to live 59.2 49.6 40.7 31.9 24.0 17.2 11.6 7.2 4 .4 2.8
a) Show the scatterplot for this data with the least squares
regression line. Find R^2. How much of the variation is
explained by the regression line?
b) Experiment with the non-linear regressions available on the
calculator. Which seem to fit? Show the scatterplot with three
different regression curves from the calculator. Label each
equation, as well as the applicable R^2.
c) Choose a regression equation to predict how many "years
left" a person has if he is now 101 years old. Can he count on
celebrating Christmas 2015?
InfoTest.javaInfoTest.javapackage assignment1;
importstatic org.junit.Assert.*;
import org.junit.Test;
publicclassInfoTest{
@Test
publicvoid testInfo(){
Info tempInfo =newInfo();
assertNotNull(tempInfo.tmp);
}
@Test
publicvoid testInsert(){
Info tempInfo =newInfo();
2. // Insert into an empty list
tempInfo.insert(30);
assertEquals(30, tempInfo.get(0));
// Insert an item to be placed at the beginning of the list
tempInfo.insert(4);
assertEquals(4, tempInfo.get(0));
assertEquals(30, tempInfo.get(1));
// Insert an item to be placed at the end of the list
tempInfo.insert(20);
assertEquals(20, tempInfo.get(1));
assertEquals(30, tempInfo.get(2));
// Insert an which already exists
tempInfo.insert(20);
assertEquals(4, tempInfo.get(0));
assertEquals(20, tempInfo.get(1));
assertEquals(30, tempInfo.get(2));
}
@Test
publicvoid testDelete(){
Info tempInfo =newInfo();
tempInfo.insert(15);
tempInfo.insert(5);
tempInfo.insert(10);
// delete from the middle
tempInfo.delete(10);
assertEquals(5, tempInfo.get(0));
assertEquals(15, tempInfo.get(1));
// delete from the beginning
tempInfo.insert(10);
3. tempInfo.delete(5);
assertEquals(10, tempInfo.get(0));
assertEquals(15, tempInfo.get(1));
// delete from the end
tempInfo.insert(5);
tempInfo.delete(15);
assertEquals(5, tempInfo.get(0));
assertEquals(10, tempInfo.get(1));
// delete something that does not exist
tempInfo.insert(15);
tempInfo.delete(7);
assertEquals(5, tempInfo.get(0));
assertEquals(10, tempInfo.get(1));
assertEquals(15, tempInfo.get(1));
}
@Test
publicvoid testGet(){
Info tempInfo =newInfo();
tempInfo.insert(15);
tempInfo.insert(5);
tempInfo.insert(10);
// get items at the beginning, middle, and end of the list
assertEquals(5, tempInfo.get(0));
assertEquals(10, tempInfo.get(1));
assertEquals(15, tempInfo.get(2));
// get an unexisting item
assertNull(tempInfo.get(3));
}
@Test
4. publicvoid testCount(){
Info tempInfo =newInfo();
// count the items in an empty list
assertEquals(0, tempInfo.count());
// count the items in a list with 1 item
tempInfo.insert(15);
assertEquals(1, tempInfo.count());
// count the items in a list with 2 items
tempInfo.insert(5);
assertEquals(2, tempInfo.count());
// count the items in a list with 3 items
tempInfo.insert(10);
assertEquals(3, tempInfo.count());
}
@Test
publicvoid testCopy(){
Info tempInfo =newInfo();
tempInfo.insert(15);
tempInfo.insert(5);
tempInfo.insert(10);
tempInfo.insert(17);
tempInfo.insert(50);
tempInfo.insert(3);
tempInfo.insert(7);
tempInfo.insert(11);
tempInfo.insert(23);
// copy a set of items from the list
Info infoCopy = tempInfo.copy(3,6);
assertEquals(10, infoCopy.get(0));
5. assertEquals(11, infoCopy.get(1));
assertEquals(15, infoCopy.get(2));
assertNull(infoCopy.get(3));
// copy only 1 item
infoCopy = tempInfo.copy(7,8);
assertEquals(23, infoCopy.get(7));
// copy out of bounds
infoCopy = tempInfo.copy(10,12);
assertNull(infoCopy);
}
@Test
publicvoid testMerge(){
/*
* merge two lists with no duplicates
*/
Info tempInfo =newInfo();
tempInfo.insert(15);
tempInfo.insert(5);
tempInfo.insert(10);
Info merge =newInfo();
merge.insert(7);
merge.insert(1);
merge.insert(23);
merge.insert(9);
tempInfo.merge(merge);
assertEquals(7, tempInfo.count());
assertEquals(1, tempInfo.get(0));
assertEquals(5, tempInfo.get(1));
assertEquals(7, tempInfo.get(2));
assertEquals(9, tempInfo.get(3));
6. assertEquals(10, tempInfo.get(4));
assertEquals(15, tempInfo.get(5));
assertEquals(23, tempInfo.get(6));
/*
* merge lists with 2 duplicates
*/
tempInfo =newInfo();
tempInfo.insert(15);
tempInfo.insert(5);
tempInfo.insert(10);
merge =newInfo();
merge.insert(5);
merge.insert(15);
merge.insert(9);
tempInfo.merge(merge);
assertEquals(4, tempInfo.count());
assertEquals(5, tempInfo.get(0));
assertEquals(9, tempInfo.get(1));
assertEquals(10, tempInfo.get(2));
assertEquals(15, tempInfo.get(3));
/*
* merge the list with an empty list
*/
tempInfo =newInfo();
tempInfo.insert(15);
tempInfo.insert(5);
tempInfo.insert(10);
merge =newInfo();
tempInfo.merge(merge);
assertEquals(3, tempInfo.count());
7. assertEquals(5, tempInfo.get(0));
assertEquals(10, tempInfo.get(1));
assertEquals(15, tempInfo.get(2));
}
@Test
publicvoid testIndexOf(){
Info tempInfo =newInfo();
tempInfo.insert(5);
// get the index of the element in a list with one item
assertEquals(0, tempInfo.indexOf(5));
tempInfo.insert(15);
tempInfo.insert(10);
// get the index of the element in the middle
assertEquals(1, tempInfo.indexOf(10));
// get the index of an unexisting object
assertEquals(-1, tempInfo.indexOf(20));
}
@Test
publicvoid testToArray(){
Info tempInfo =newInfo();
// get the array of an empty object
Object[] infoArray = tempInfo.toArray();
assertTrue(infoArray.length ==0);
tempInfo.insert(15);
tempInfo.insert(5);
tempInfo.insert(10);
tempInfo.insert(17);
tempInfo.insert(50);
8. tempInfo.insert(3);
tempInfo.insert(7);
tempInfo.insert(11);
tempInfo.insert(23);
tempInfo.insert(61);
// get the array with several elements
infoArray = tempInfo.toArray();
for(int i =0; i <10; i++){
assertTrue(infoArray[i]== tempInfo.get(i));
}
}
}
Info.javaInfo.javapackage info;
publicclassInfo{
/**
* Class Info is a implementation for a collection of Compara
ble objects.
* All values are kept in ascending order and have a position
where 0 is the position of the first object in the collection.
* There is no maximum size for the collection.
*/
// Temporary holder for the collection. To be updated in final i
mplementation.
Comparable tmp;
/**
* Creates an empty Info object to hold Comparable objects.
*/
Info(){
9. tmp =null;
}
/**
* Inserts the parameter into the Info object so the values in t
he Info object are in ascending order.
* If the value is already in the array, do not insert it.
* @param obj the Comparable object to insert
*/
void insert (Comparable obj){
}
/**
* Delete the parameter object if it is in the Info object.
* @param obj the Comparable object to delete
*/
void delete (Comparable obj){
}
/**
* Return the Comparable object at the position given. If the
parameter position is out of bounds, return null.
* @param x the position of the Comparable object in the Inf
o object to access
* @return object found in Info object
*/
Object get (int x){
returnnull;
}
/**
* Return the number of Comparable objects are in the Info o
bject
* @return count of Comparable objects
*/
10. int count (){
returnInteger.MIN_VALUE;
}
/**
* Return an Info object that is a copy of the contents from th
e first parameter position to the last parameter
* position. If the bounds given are out of bounds, return nul
l.
* @param x first position to copy
* @param y last position to copy
* @return new Info object
*/
Info copy (int x,int y){
returnnull;
}
/**
* Merge the current Info object with the parameter Info obje
ct.
* The results should be a new Info object in ascending order
with no duplicates.
* @param list Info object to merge with the current Info obj
ect
* @return new Info object with merged values
*/
Info merge (Info list){
returnnull;
}
/**
* Return the position of the parameter in the Info object.
* If the Comparable object is not in the Info object, return -
1.
* @param obj Comparable object to search for
* @return integer position of parameter in Info object
11. */
int indexOf (Comparable obj){
returnInteger.MAX_VALUE;
}
/**
* Copies the contents of the collection Info object to an arra
y. The array contains the
* same number of elements as the original collection and obj
ects are in the same order.
* @return array of Comparable objects
*/
Object[] toArray(){
returnnull;
}
}
CSE360 Assignment 5(2).docx
CSE360 Fall 2015
Assignment 5 Due Nov 6 3PM
This is an assignment in writing and testing unit level code.
You may work solo or in a pair. Be sure to put both your names
on the completed work (all files).
In assignment 1, you wrote the Junit cases for the class Info. It
is now time to implement the code for Info and test it.
<<interface>>
Comparable
Item
Info
12. · str:String
· val:int
· list:Node
· numNodes:int
+ compareTo(Comparable): int
+ compareTo(Item):int
+ toString():String
+ Info()
+ insert (Item): void
+ delete (Item): void
+ get (int): Item
+ count(): int
+ copy(int, int): Info
+ merge(Info): Info
+ indexOf(Item): int
+ toString(): String
· Node
· data: Item
· next: Node
13. + Node (Item)
The diagram above shows that an Item consists of two data
attributes: a String and an integer: An Info contains a Node and
an integer. The Node class is implemented as an internal or
private class in Info. This is shown above by the circle with the
lines.
Note that the toArray method has now been replaced by the
toString method.(In the template you have toArray, change it to
toString now)
Info must be implemented as a singly linked list using the
internal Node class. The variable list is a reference to the first
node in the list and numNodes hold the current count of the
nodes. Using another implementation including the Java
Collections Framework is not acceptable.
Also, all code must meet the style and documentation
requirements covered in class.
Test your code using your Junit tests. Make
changes/improvements to the tests as needed.
Submit your InfoTest.java, Info.java and Item.java files on
Blackboard (Assignment 5) by the deadline. Late submittals are
penalized. (InfoTest.java and Info.java are given, you just need
to modify it, For the Item.java you need to create your own
version)