SlideShare a Scribd company logo
Martian Cubics and Unit Testing
You must implement all of the data members and methods described below. RAM is more
limited on NASA missions than on your home computer, so you may NOT add any instance
variables or static variables to this class other than those described below. You may add methods
of your own, as long as they are private. The data type class you are writing is a very general
class that could be of use in a wide variety of projects at NASA in their Mars research, so take
care in your work!
Implement
eval -- this method takes one parameter (DoubleWithAppx), evaluates the Martian cubic at the
point represented by the parameter and returns a DoubleWithAppx representing the result of that
evaluation. (i.e., if your Martian cubic is 5x^3-3x^2+2x+4, and you call eval(5), it should return
564.)
My Code:
public class MartianCubic {
private final DoubleWithAppx a ;
private final DoubleWithAppx b;
private final DoubleWithAppx c;
private final DoubleWithAppx d;
public MartianCubic() {
a = new DoubleWithAppx(0);
b = new DoubleWithAppx(0);
c = new DoubleWithAppx(0);
d = new DoubleWithAppx(0);
}
public MartianCubic(DoubleWithAppx dIn) {
d = dIn;
a = new DoubleWithAppx(0);
b = new DoubleWithAppx(0);
c = new DoubleWithAppx(0);
}
public MartianCubic(DoubleWithAppx cIn, DoubleWithAppx dIn) {
c = cIn;
d = dIn;
a = new DoubleWithAppx(0);
b = new DoubleWithAppx(0);
}
public MartianCubic(DoubleWithAppx bIn, DoubleWithAppx cIn, DoubleWithAppx dIn) {
this.b = bIn;
this.c = cIn;
this.d = dIn;
a = new DoubleWithAppx(0);
}
public MartianCubic(DoubleWithAppx aIn, DoubleWithAppx bIn, DoubleWithAppx cIn,
DoubleWithAppx dIn) {
this.a = aIn;
this.b = bIn;
this.c = cIn;
this.d = dIn;
}
public MartianCubic(MartianCubic other) {
this(
other.getA(),
other.getB(),
other.getC(),
other.getD()
);
}
public DoubleWithAppx getA() {
return a;
}
public DoubleWithAppx getB() {
return b;
}
public DoubleWithAppx getC() {
return c;
}
public DoubleWithAppx getD() {
return d;
}
public DoubleWithAppx eval(DoubleWithAppx x) {
//HINT: Think about how to chain method calls to make this compact.
}
public boolean equals (Object other) {
if (other == null) {
return false;
}
else if (this.getClass()!=other.getClass()) {
return false;
}
else {
MartianCubic casted = (MartianCubic)other;
return (
a.equals(casted.a) &&
b.equals(casted.b) &&
c.equals(casted.c) &&
d.equals(casted.d)
);
}
}
Solution
//solution
package ex;
public class MartianCubic {
private final DoubleWithAppx a ;
private final DoubleWithAppx b;
private final DoubleWithAppx c;
private final DoubleWithAppx d;
public MartianCubic() {
a = new DoubleWithAppx(0);
b = new DoubleWithAppx(0);
c = new DoubleWithAppx(0);
d = new DoubleWithAppx(0);
}
public MartianCubic(DoubleWithAppx dIn) {
d = dIn;
a = new DoubleWithAppx(0);
b = new DoubleWithAppx(0);
c = new DoubleWithAppx(0);
}
public MartianCubic(DoubleWithAppx cIn, DoubleWithAppx dIn) {
c = cIn;
d = dIn;
a = new DoubleWithAppx(0);
b = new DoubleWithAppx(0);
}
public MartianCubic(DoubleWithAppx bIn, DoubleWithAppx cIn, DoubleWithAppx dIn) {
this.b = bIn;
this.c = cIn;
this.d = dIn;
a = new DoubleWithAppx(0);
}
public MartianCubic(DoubleWithAppx aIn, DoubleWithAppx bIn, DoubleWithAppx cIn,
DoubleWithAppx dIn) {
this.a = aIn;
this.b = bIn;
this.c = cIn;
this.d = dIn;
}
public MartianCubic(MartianCubic other) {
this(
other.getA(),
other.getB(),
other.getC(),
other.getD()
);
}
public DoubleWithAppx getA() {
return a;
}
public DoubleWithAppx getB() {
return b;
}
public DoubleWithAppx getC() {
return c;
}
public DoubleWithAppx getD() {
return d;
}
public DoubleWithAppx eval(DoubleWithAppx x) {
//HINT: Think about how to chain method calls to make this compact.
double ans;
ans= getA().getValue()* Math.pow(x.getValue(),3)-
getB().getValue()*Math.pow(x.getValue(),2)+getC().getValue()*x.getValue()+getD().getValue()
;
return new DoubleWithAppx((int) ans);
}
public boolean equals (Object other) {
if (other == null) {
return false;
}
else if (this.getClass()!=other.getClass()) {
return false;
}
else {
MartianCubic casted = (MartianCubic)other;
return (
a.equals(casted.a) &&
b.equals(casted.b) &&
c.equals(casted.c) &&
d.equals(casted.d)
);
}
}
}

More Related Content

Similar to Martian Cubics and Unit TestingYou must implement all of the data .pdf

Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional ProgrammingEelco Visser
 
Type script, for dummies
Type script, for dummiesType script, for dummies
Type script, for dummies
santiagoaguiar
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
dbrienmhompsonkath75
 
Functional Programming in Java 8
Functional Programming in Java 8Functional Programming in Java 8
Functional Programming in Java 8
Omar Bashir
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
Mark Kilgard
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
Kapish Joshi
 
Mobile Day - React Native
Mobile Day - React NativeMobile Day - React Native
Mobile Day - React Native
Software Guru
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
Divante
 
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfCircle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
ANJALIENTERPRISES1
 
Hi,I have modified the Point.java file as per your requirement.P.pdf
Hi,I have modified the Point.java file as per your requirement.P.pdfHi,I have modified the Point.java file as per your requirement.P.pdf
Hi,I have modified the Point.java file as per your requirement.P.pdf
anokhijew
 
DevoxxPL: JRebel Under The Covers
DevoxxPL: JRebel Under The CoversDevoxxPL: JRebel Under The Covers
DevoxxPL: JRebel Under The Covers
Simon Maple
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
Caridy Patino
 
Testing Hadoop jobs with MRUnit
Testing Hadoop jobs with MRUnitTesting Hadoop jobs with MRUnit
Testing Hadoop jobs with MRUnit
Eric Wendelin
 
‫Chapter3 inheritance
‫Chapter3 inheritance‫Chapter3 inheritance
‫Chapter3 inheritance
Mahmoud Alfarra
 
JUnit PowerUp
JUnit PowerUpJUnit PowerUp
JUnit PowerUp
James McGivern
 
Language fundamentals ocjp
Language fundamentals ocjpLanguage fundamentals ocjp
Language fundamentals ocjp
Bhavishya sharma
 
Android Data Persistence
Android Data PersistenceAndroid Data Persistence
Android Data Persistence
Romain Rochegude
 
“SOLID principles in PHP – how to apply them in PHP and why should we care“ b...
“SOLID principles in PHP – how to apply them in PHP and why should we care“ b...“SOLID principles in PHP – how to apply them in PHP and why should we care“ b...
“SOLID principles in PHP – how to apply them in PHP and why should we care“ b...
DevClub_lv
 
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdfListings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
RAJATCHUGH12
 

Similar to Martian Cubics and Unit TestingYou must implement all of the data .pdf (20)

Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional Programming
 
Type script, for dummies
Type script, for dummiesType script, for dummies
Type script, for dummies
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
 
Functional Programming in Java 8
Functional Programming in Java 8Functional Programming in Java 8
Functional Programming in Java 8
 
CSharp v1.0.2
CSharp v1.0.2CSharp v1.0.2
CSharp v1.0.2
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
 
Java Inheritance
Java InheritanceJava Inheritance
Java Inheritance
 
Mobile Day - React Native
Mobile Day - React NativeMobile Day - React Native
Mobile Day - React Native
 
Why is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenariosWhy is crud a bad idea - focus on real scenarios
Why is crud a bad idea - focus on real scenarios
 
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdfCircle.javaimport java.text.DecimalFormat;public class Circle {.pdf
Circle.javaimport java.text.DecimalFormat;public class Circle {.pdf
 
Hi,I have modified the Point.java file as per your requirement.P.pdf
Hi,I have modified the Point.java file as per your requirement.P.pdfHi,I have modified the Point.java file as per your requirement.P.pdf
Hi,I have modified the Point.java file as per your requirement.P.pdf
 
DevoxxPL: JRebel Under The Covers
DevoxxPL: JRebel Under The CoversDevoxxPL: JRebel Under The Covers
DevoxxPL: JRebel Under The Covers
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScript
 
Testing Hadoop jobs with MRUnit
Testing Hadoop jobs with MRUnitTesting Hadoop jobs with MRUnit
Testing Hadoop jobs with MRUnit
 
‫Chapter3 inheritance
‫Chapter3 inheritance‫Chapter3 inheritance
‫Chapter3 inheritance
 
JUnit PowerUp
JUnit PowerUpJUnit PowerUp
JUnit PowerUp
 
Language fundamentals ocjp
Language fundamentals ocjpLanguage fundamentals ocjp
Language fundamentals ocjp
 
Android Data Persistence
Android Data PersistenceAndroid Data Persistence
Android Data Persistence
 
“SOLID principles in PHP – how to apply them in PHP and why should we care“ b...
“SOLID principles in PHP – how to apply them in PHP and why should we care“ b...“SOLID principles in PHP – how to apply them in PHP and why should we care“ b...
“SOLID principles in PHP – how to apply them in PHP and why should we care“ b...
 
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdfListings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
Listings for BinaryHeap.java and BinaryHeapTest.java are shown in th.pdf
 

More from ellanorfelicityri239

How to Read the City Evaluating evidence to generate informed urban .pdf
How to Read the City Evaluating evidence to generate informed urban .pdfHow to Read the City Evaluating evidence to generate informed urban .pdf
How to Read the City Evaluating evidence to generate informed urban .pdf
ellanorfelicityri239
 
How do transpiration, cohesion and adhesion all work together to pro.pdf
How do transpiration, cohesion and adhesion all work together to pro.pdfHow do transpiration, cohesion and adhesion all work together to pro.pdf
How do transpiration, cohesion and adhesion all work together to pro.pdf
ellanorfelicityri239
 
How can the Internet be used for competitive advantage in business .pdf
How can the Internet be used for competitive advantage in business .pdfHow can the Internet be used for competitive advantage in business .pdf
How can the Internet be used for competitive advantage in business .pdf
ellanorfelicityri239
 
give an example of an qualitative variablegive an example of.pdf
give an example of an qualitative variablegive an example of.pdfgive an example of an qualitative variablegive an example of.pdf
give an example of an qualitative variablegive an example of.pdf
ellanorfelicityri239
 
Dynamic biological process influence population density, dispersion a.pdf
Dynamic biological process influence population density, dispersion a.pdfDynamic biological process influence population density, dispersion a.pdf
Dynamic biological process influence population density, dispersion a.pdf
ellanorfelicityri239
 
Discuss some disadvantages of viable counts of microorganisms.So.pdf
Discuss some disadvantages of viable counts of microorganisms.So.pdfDiscuss some disadvantages of viable counts of microorganisms.So.pdf
Discuss some disadvantages of viable counts of microorganisms.So.pdf
ellanorfelicityri239
 
Describe the pathophysiology, clinical manifestations, diagnostic te.pdf
Describe the pathophysiology, clinical manifestations, diagnostic te.pdfDescribe the pathophysiology, clinical manifestations, diagnostic te.pdf
Describe the pathophysiology, clinical manifestations, diagnostic te.pdf
ellanorfelicityri239
 
Could you please do it in R program 1. Assume that we draw n data v.pdf
Could you please do it in R program 1. Assume that we draw n data v.pdfCould you please do it in R program 1. Assume that we draw n data v.pdf
Could you please do it in R program 1. Assume that we draw n data v.pdf
ellanorfelicityri239
 
Class diagrams are used to define the dynamic behavior of an executi.pdf
Class diagrams are used to define the dynamic behavior of an executi.pdfClass diagrams are used to define the dynamic behavior of an executi.pdf
Class diagrams are used to define the dynamic behavior of an executi.pdf
ellanorfelicityri239
 
Can someone please help me with my ICD 10 II assignment...A 47-yea.pdf
Can someone please help me with my ICD 10 II assignment...A 47-yea.pdfCan someone please help me with my ICD 10 II assignment...A 47-yea.pdf
Can someone please help me with my ICD 10 II assignment...A 47-yea.pdf
ellanorfelicityri239
 
CAD is a critical technology for an integrated product development p.pdf
CAD is a critical technology for an integrated product development p.pdfCAD is a critical technology for an integrated product development p.pdf
CAD is a critical technology for an integrated product development p.pdf
ellanorfelicityri239
 
Byzantine influence can be seen in Russian literature because the Ru.pdf
Byzantine influence can be seen in Russian literature because  the Ru.pdfByzantine influence can be seen in Russian literature because  the Ru.pdf
Byzantine influence can be seen in Russian literature because the Ru.pdf
ellanorfelicityri239
 
balance sheet Google Search MC Qu. 122 An example of an operating... .pdf
balance sheet Google Search MC Qu. 122 An example of an operating... .pdfbalance sheet Google Search MC Qu. 122 An example of an operating... .pdf
balance sheet Google Search MC Qu. 122 An example of an operating... .pdf
ellanorfelicityri239
 
Write a 1-2 page essay researching biological science and its famous.pdf
Write a 1-2 page essay researching biological science and its famous.pdfWrite a 1-2 page essay researching biological science and its famous.pdf
Write a 1-2 page essay researching biological science and its famous.pdf
ellanorfelicityri239
 
Why do plants in early stage exhibit high levels of tolerance Early .pdf
Why do plants in early stage exhibit high levels of tolerance Early .pdfWhy do plants in early stage exhibit high levels of tolerance Early .pdf
Why do plants in early stage exhibit high levels of tolerance Early .pdf
ellanorfelicityri239
 
Which researcher(s) paralyzed subjects using Scoline in a classical .pdf
Which researcher(s) paralyzed subjects using Scoline in a classical .pdfWhich researcher(s) paralyzed subjects using Scoline in a classical .pdf
Which researcher(s) paralyzed subjects using Scoline in a classical .pdf
ellanorfelicityri239
 
Which of the following statements is NOT accurate about Mycobacteriu.pdf
Which of the following statements is NOT accurate about Mycobacteriu.pdfWhich of the following statements is NOT accurate about Mycobacteriu.pdf
Which of the following statements is NOT accurate about Mycobacteriu.pdf
ellanorfelicityri239
 
Which of the following is likely to increase the electrical conductiv.pdf
Which of the following is likely to increase the electrical conductiv.pdfWhich of the following is likely to increase the electrical conductiv.pdf
Which of the following is likely to increase the electrical conductiv.pdf
ellanorfelicityri239
 
What is the difference between endogenous and exogenous infections .pdf
What is the difference between endogenous and exogenous infections  .pdfWhat is the difference between endogenous and exogenous infections  .pdf
What is the difference between endogenous and exogenous infections .pdf
ellanorfelicityri239
 
What is a scattergramscatterdotscatterplot (different names for sa.pdf
What is a scattergramscatterdotscatterplot (different names for sa.pdfWhat is a scattergramscatterdotscatterplot (different names for sa.pdf
What is a scattergramscatterdotscatterplot (different names for sa.pdf
ellanorfelicityri239
 

More from ellanorfelicityri239 (20)

How to Read the City Evaluating evidence to generate informed urban .pdf
How to Read the City Evaluating evidence to generate informed urban .pdfHow to Read the City Evaluating evidence to generate informed urban .pdf
How to Read the City Evaluating evidence to generate informed urban .pdf
 
How do transpiration, cohesion and adhesion all work together to pro.pdf
How do transpiration, cohesion and adhesion all work together to pro.pdfHow do transpiration, cohesion and adhesion all work together to pro.pdf
How do transpiration, cohesion and adhesion all work together to pro.pdf
 
How can the Internet be used for competitive advantage in business .pdf
How can the Internet be used for competitive advantage in business .pdfHow can the Internet be used for competitive advantage in business .pdf
How can the Internet be used for competitive advantage in business .pdf
 
give an example of an qualitative variablegive an example of.pdf
give an example of an qualitative variablegive an example of.pdfgive an example of an qualitative variablegive an example of.pdf
give an example of an qualitative variablegive an example of.pdf
 
Dynamic biological process influence population density, dispersion a.pdf
Dynamic biological process influence population density, dispersion a.pdfDynamic biological process influence population density, dispersion a.pdf
Dynamic biological process influence population density, dispersion a.pdf
 
Discuss some disadvantages of viable counts of microorganisms.So.pdf
Discuss some disadvantages of viable counts of microorganisms.So.pdfDiscuss some disadvantages of viable counts of microorganisms.So.pdf
Discuss some disadvantages of viable counts of microorganisms.So.pdf
 
Describe the pathophysiology, clinical manifestations, diagnostic te.pdf
Describe the pathophysiology, clinical manifestations, diagnostic te.pdfDescribe the pathophysiology, clinical manifestations, diagnostic te.pdf
Describe the pathophysiology, clinical manifestations, diagnostic te.pdf
 
Could you please do it in R program 1. Assume that we draw n data v.pdf
Could you please do it in R program 1. Assume that we draw n data v.pdfCould you please do it in R program 1. Assume that we draw n data v.pdf
Could you please do it in R program 1. Assume that we draw n data v.pdf
 
Class diagrams are used to define the dynamic behavior of an executi.pdf
Class diagrams are used to define the dynamic behavior of an executi.pdfClass diagrams are used to define the dynamic behavior of an executi.pdf
Class diagrams are used to define the dynamic behavior of an executi.pdf
 
Can someone please help me with my ICD 10 II assignment...A 47-yea.pdf
Can someone please help me with my ICD 10 II assignment...A 47-yea.pdfCan someone please help me with my ICD 10 II assignment...A 47-yea.pdf
Can someone please help me with my ICD 10 II assignment...A 47-yea.pdf
 
CAD is a critical technology for an integrated product development p.pdf
CAD is a critical technology for an integrated product development p.pdfCAD is a critical technology for an integrated product development p.pdf
CAD is a critical technology for an integrated product development p.pdf
 
Byzantine influence can be seen in Russian literature because the Ru.pdf
Byzantine influence can be seen in Russian literature because  the Ru.pdfByzantine influence can be seen in Russian literature because  the Ru.pdf
Byzantine influence can be seen in Russian literature because the Ru.pdf
 
balance sheet Google Search MC Qu. 122 An example of an operating... .pdf
balance sheet Google Search MC Qu. 122 An example of an operating... .pdfbalance sheet Google Search MC Qu. 122 An example of an operating... .pdf
balance sheet Google Search MC Qu. 122 An example of an operating... .pdf
 
Write a 1-2 page essay researching biological science and its famous.pdf
Write a 1-2 page essay researching biological science and its famous.pdfWrite a 1-2 page essay researching biological science and its famous.pdf
Write a 1-2 page essay researching biological science and its famous.pdf
 
Why do plants in early stage exhibit high levels of tolerance Early .pdf
Why do plants in early stage exhibit high levels of tolerance Early .pdfWhy do plants in early stage exhibit high levels of tolerance Early .pdf
Why do plants in early stage exhibit high levels of tolerance Early .pdf
 
Which researcher(s) paralyzed subjects using Scoline in a classical .pdf
Which researcher(s) paralyzed subjects using Scoline in a classical .pdfWhich researcher(s) paralyzed subjects using Scoline in a classical .pdf
Which researcher(s) paralyzed subjects using Scoline in a classical .pdf
 
Which of the following statements is NOT accurate about Mycobacteriu.pdf
Which of the following statements is NOT accurate about Mycobacteriu.pdfWhich of the following statements is NOT accurate about Mycobacteriu.pdf
Which of the following statements is NOT accurate about Mycobacteriu.pdf
 
Which of the following is likely to increase the electrical conductiv.pdf
Which of the following is likely to increase the electrical conductiv.pdfWhich of the following is likely to increase the electrical conductiv.pdf
Which of the following is likely to increase the electrical conductiv.pdf
 
What is the difference between endogenous and exogenous infections .pdf
What is the difference between endogenous and exogenous infections  .pdfWhat is the difference between endogenous and exogenous infections  .pdf
What is the difference between endogenous and exogenous infections .pdf
 
What is a scattergramscatterdotscatterplot (different names for sa.pdf
What is a scattergramscatterdotscatterplot (different names for sa.pdfWhat is a scattergramscatterdotscatterplot (different names for sa.pdf
What is a scattergramscatterdotscatterplot (different names for sa.pdf
 

Recently uploaded

The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 

Recently uploaded (20)

The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 

Martian Cubics and Unit TestingYou must implement all of the data .pdf

  • 1. Martian Cubics and Unit Testing You must implement all of the data members and methods described below. RAM is more limited on NASA missions than on your home computer, so you may NOT add any instance variables or static variables to this class other than those described below. You may add methods of your own, as long as they are private. The data type class you are writing is a very general class that could be of use in a wide variety of projects at NASA in their Mars research, so take care in your work! Implement eval -- this method takes one parameter (DoubleWithAppx), evaluates the Martian cubic at the point represented by the parameter and returns a DoubleWithAppx representing the result of that evaluation. (i.e., if your Martian cubic is 5x^3-3x^2+2x+4, and you call eval(5), it should return 564.) My Code: public class MartianCubic { private final DoubleWithAppx a ; private final DoubleWithAppx b; private final DoubleWithAppx c; private final DoubleWithAppx d; public MartianCubic() { a = new DoubleWithAppx(0); b = new DoubleWithAppx(0); c = new DoubleWithAppx(0); d = new DoubleWithAppx(0); } public MartianCubic(DoubleWithAppx dIn) { d = dIn; a = new DoubleWithAppx(0); b = new DoubleWithAppx(0); c = new DoubleWithAppx(0); } public MartianCubic(DoubleWithAppx cIn, DoubleWithAppx dIn) { c = cIn; d = dIn;
  • 2. a = new DoubleWithAppx(0); b = new DoubleWithAppx(0); } public MartianCubic(DoubleWithAppx bIn, DoubleWithAppx cIn, DoubleWithAppx dIn) { this.b = bIn; this.c = cIn; this.d = dIn; a = new DoubleWithAppx(0); } public MartianCubic(DoubleWithAppx aIn, DoubleWithAppx bIn, DoubleWithAppx cIn, DoubleWithAppx dIn) { this.a = aIn; this.b = bIn; this.c = cIn; this.d = dIn; } public MartianCubic(MartianCubic other) { this( other.getA(), other.getB(), other.getC(), other.getD() ); } public DoubleWithAppx getA() { return a; } public DoubleWithAppx getB() { return b; }
  • 3. public DoubleWithAppx getC() { return c; } public DoubleWithAppx getD() { return d; } public DoubleWithAppx eval(DoubleWithAppx x) { //HINT: Think about how to chain method calls to make this compact. } public boolean equals (Object other) { if (other == null) { return false; } else if (this.getClass()!=other.getClass()) { return false; } else { MartianCubic casted = (MartianCubic)other; return ( a.equals(casted.a) && b.equals(casted.b) && c.equals(casted.c) && d.equals(casted.d) ); } } Solution
  • 4. //solution package ex; public class MartianCubic { private final DoubleWithAppx a ; private final DoubleWithAppx b; private final DoubleWithAppx c; private final DoubleWithAppx d; public MartianCubic() { a = new DoubleWithAppx(0); b = new DoubleWithAppx(0); c = new DoubleWithAppx(0); d = new DoubleWithAppx(0); } public MartianCubic(DoubleWithAppx dIn) { d = dIn; a = new DoubleWithAppx(0); b = new DoubleWithAppx(0); c = new DoubleWithAppx(0); } public MartianCubic(DoubleWithAppx cIn, DoubleWithAppx dIn) { c = cIn; d = dIn; a = new DoubleWithAppx(0); b = new DoubleWithAppx(0); } public MartianCubic(DoubleWithAppx bIn, DoubleWithAppx cIn, DoubleWithAppx dIn) { this.b = bIn; this.c = cIn; this.d = dIn; a = new DoubleWithAppx(0); }
  • 5. public MartianCubic(DoubleWithAppx aIn, DoubleWithAppx bIn, DoubleWithAppx cIn, DoubleWithAppx dIn) { this.a = aIn; this.b = bIn; this.c = cIn; this.d = dIn; } public MartianCubic(MartianCubic other) { this( other.getA(), other.getB(), other.getC(), other.getD() ); } public DoubleWithAppx getA() { return a; } public DoubleWithAppx getB() { return b; } public DoubleWithAppx getC() { return c; } public DoubleWithAppx getD() { return d; }
  • 6. public DoubleWithAppx eval(DoubleWithAppx x) { //HINT: Think about how to chain method calls to make this compact. double ans; ans= getA().getValue()* Math.pow(x.getValue(),3)- getB().getValue()*Math.pow(x.getValue(),2)+getC().getValue()*x.getValue()+getD().getValue() ; return new DoubleWithAppx((int) ans); } public boolean equals (Object other) { if (other == null) { return false; } else if (this.getClass()!=other.getClass()) { return false; } else { MartianCubic casted = (MartianCubic)other; return ( a.equals(casted.a) && b.equals(casted.b) && c.equals(casted.c) && d.equals(casted.d) ); } } }