Question
TheExtremesclass represents the range ofIntegervalues. Fill in theExtremesmethods. In the constructor, setminandmaxto the minimum and maximum value ofInteger. UseInteger.MIN_VALUEandInteger.MAX_VALUE. Also fill in theminDiffandmaxDiffmethods to return
TheExtremesclass represents the range ofIntegervalues.
Fill in theExtremesmethods. In the constructor, setminandmaxto the minimum and maximum value ofInteger. UseInteger.MIN_VALUEandInteger.MAX_VALUE. Also fill in theminDiffandmaxDiffmethods to return the difference between the users guess and the actual max/min values ofInteger.
Main
Inmain, use the comments as a guide to ask the user to guess the maximum and minimum values. Compute the difference between the guess and the values, then print it out.
Be aware that if you choose a number too big or too small, it will cause an error since the number cannot be stored.
The results inmainshould look something like this:
Guess the maximum Integer value: 543214 You were off by 2146940433 Guess the minimum Integer value: 2145678321 You were off by 1805327
2.9.8: Guess the number!
importjava.util.Scanner; importjava.lang.*; publicclassExtremeMain { publicstaticvoidmain(String[]args) { //CreateaScannerobject //CreateanExtremesobject //AsktheusertoguessthemaximumvalueofanInteger //Computeanddisplaythedifference //betweenthemaxandtheguess //AsktheusertoguesstheminimumvalueofanInteger //Computeanddisplaythedifference //betweentheminandtheguess } }
publicclassExtremes { Integermin; Integermax; //Constructor publicExtremes() { //Setminandmaxvalues } //Returnsthedifference //max-number publicIntegermaxDiff(Integernumber) { } //Returnsthedifference //min-number publicIntegerminDiff(Integernumber) { } //ReturnsaStringrepresentation //intheform //[min,max] publicStringtoString() { return"["+min+","+max+"]"; } }
Need help solving this problem
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started