SlideShare a Scribd company logo
1 of 6
Download to read offline
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 dummiessantiagoaguiar
 
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.pdfdbrienmhompsonkath75
 
Functional Programming in Java 8
Functional Programming in Java 8Functional Programming in Java 8
Functional Programming in Java 8Omar Bashir
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingMark Kilgard
 
Mobile Day - React Native
Mobile Day - React NativeMobile Day - React Native
Mobile Day - React NativeSoftware 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 scenariosDivante
 
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 {.pdfANJALIENTERPRISES1
 
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.pdfanokhijew
 
DevoxxPL: JRebel Under The Covers
DevoxxPL: JRebel Under The CoversDevoxxPL: JRebel Under The Covers
DevoxxPL: JRebel Under The CoversSimon Maple
 
MiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptMiamiJS - The Future of JavaScript
MiamiJS - The Future of JavaScriptCaridy Patino
 
Testing Hadoop jobs with MRUnit
Testing Hadoop jobs with MRUnitTesting Hadoop jobs with MRUnit
Testing Hadoop jobs with MRUnitEric Wendelin
 
Language fundamentals ocjp
Language fundamentals ocjpLanguage fundamentals ocjp
Language fundamentals ocjpBhavishya sharma
 
“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.pdfRAJATCHUGH12
 

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 .pdfellanorfelicityri239
 
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.pdfellanorfelicityri239
 
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 .pdfellanorfelicityri239
 
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.pdfellanorfelicityri239
 
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.pdfellanorfelicityri239
 
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.pdfellanorfelicityri239
 
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.pdfellanorfelicityri239
 
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.pdfellanorfelicityri239
 
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.pdfellanorfelicityri239
 
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.pdfellanorfelicityri239
 
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.pdfellanorfelicityri239
 
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.pdfellanorfelicityri239
 
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... .pdfellanorfelicityri239
 
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.pdfellanorfelicityri239
 
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 .pdfellanorfelicityri239
 
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 .pdfellanorfelicityri239
 
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.pdfellanorfelicityri239
 
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.pdfellanorfelicityri239
 
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 .pdfellanorfelicityri239
 
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.pdfellanorfelicityri239
 

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

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 

Recently uploaded (20)

A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 

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) ); } } }