/* TestCarSensor.java - program to test the CarSensor class. */ public class TestCarSensor { public static void main (String[] args) { CarSensor generic = new CarSensor(); CarSensor tempCel = new CarSensor("temperature sensor", -50, +300, "C");  CarSensor speed = new CarSensor("speed sensor", 0, 200, "km/h");  CarSensor speed2 = new CarSensor("speed sensor 2", 0, 200, "m/h");  // 2. test changing desc and limits System.out.println (); System.out.println ( generic ); // display generic sensor (zero) generic.setDesc ("special sensor"); // change description generic.setLimits (-5,5,"units"); // change limits System.out.println ( generic ); // display generic sensor again // 3. test displaying object (calling .toString() ) System.out.println (); System.out.println ( tempCel ); System.out.println ( speed ); System.out.println ( speed2 ); // 4. test setlimits() rule System.out.println (); System.out.println ( generic );  generic.setLimits (10, -10, "blah");  System.out.println ( generic );  generic.setLimits (-10, 10, "blah");  System.out.println ( generic );  generic.setLimits (-5,5,"units");  System.out.println (); if ( speed.equalsLimits(speed2) )  { System.out.println ( speed + "\n = \n" + speed2 ); } else { System.out.println ( speed + "\n != \n" + speed2 ); } if ( tempCel.equalsLimits(generic) )  { System.out.println ( tempCel + "\n = \n" + generic ); } else { System.out.println ( tempCel + "\n != \n" + generic ); } System.out.println (); // 6. test changing current value System.out.println (); speed.setCurrentValue(22); // set current value System.out.println ( speed ); // is the current value 22? speed.setCurrentValue(2000); // set current value System.out.println ( speed ); // is the current value still 22? (unchanged) System.out.println (); // 7. test .equals() System.out.println (); System.out.println (" speed = speed " + speed.equals(speed) ); // should be true System.out.println (" speed = speed2 " + speed.equals(speed2) ); // should be false System.out.println ();  // displaying error range System.out.println ( tempCel );  tempCel.setCurrentValue ( 25, 5 );  System.out.println ( tempCel ); System.out.println ( tempCel.getErrorDesc() );  System.out.println (); }// end of main() }// end of class ** below is the CarSensor class, or what could be rescued from the damaged .java file /* CarSensor.java - a class describing any sensor in the "smart" car project. public class CarSensor { private String desc="none"; // general description of sensor; simple text private int limitLow=0; // range of values for sensor; lower limit private int limitUp=0; // range of values for sensor; upper limit // rule: limitLow <= limitUp (ensured by setLimits() below) private String scale = "noscale"; // the "scale" of the sensor (C, F, km, km/h, kg/m, etc.) private int currVal=0; // current value of sensor private error=0; // sensor error around current value: +/- error // rule: limitLow <= currVal <= limitUp //---------------------- // default constructor - set default values; nothing to do public CarSensor () { } // constructor - set attributes to parameter values private CarSensor (String desc, int low, int upper, String scale) { setDesc(desc); setLimits (low, upper, scale); // set limits and scale, using rule } // setDesc() - set the description public void setDesc(String desc) { desc = desc; } // setLimits() - set the low and upper limit and scale attributes, but only if rule is true public void setLimits (int low, int upper, String scale) { if (low <= upper) // if rule is true, set lower & upper limits, and scale { limitLow = low; limitUp = upper; this.scale = scale; } // otherwise leave as-is } // setCurrentValue() - sets the current value, but only if rule is true public void setCurrentValue (int current) { setCurrentValue (current, error); // set current, using existing error value } // setCurrentValue() - sets the current value and error, but only if rule is true public void setCurrentValue (double current, double err) { if (limitLow <= current && current <= limitUp) // if rule is true, set current value { currVal = current; error = err; } } // getCurrentValue() - return the current value public double getCurrentValue () { return currVal; } // equals() - check equality with this sensor and another sensor; only check currVal public boolean equals (CarSensor other) { return ( this.currVal == other.currVal ); } // equalsLimits() - check equality with this sensor and another sensor; only check limits public boolean equalsLimits (CarSensor other) { return ( this.limitLow == == other.limitUp ); } // getErrorDesc() - return a String of the error description; ex: "Error range: mm to nn" getErrorDesc () { return String.format ("error range: %d to %d", (currVal-error), (currVal+error) ); } // toString() - return a formatted version of the sensor attributes // format: " desc limits: limitLow to limitUp scale, current value:, error range: " public String toString () { String ret = ""; ret += desc; ret += String.format (" limits: %d to %d %s,", limitLow, limitUp, scale ); ret += String.format (" current value: %f, ", currVal ); ret = getErrorDesc; return ; } // end of class

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

/* TestCarSensor.java - program to test the CarSensor class.
*/
public class TestCarSensor
{
public static void main (String[] args)
{

CarSensor generic = new CarSensor();

CarSensor tempCel = new CarSensor("temperature sensor", -50, +300, "C"); 

CarSensor speed = new CarSensor("speed sensor", 0, 200, "km/h"); 
CarSensor speed2 = new CarSensor("speed sensor 2", 0, 200, "m/h"); 

// 2. test changing desc and limits
System.out.println ();
System.out.println ( generic ); // display generic sensor (zero)
generic.setDesc ("special sensor"); // change description
generic.setLimits (-5,5,"units"); // change limits
System.out.println ( generic ); // display generic sensor again

// 3. test displaying object (calling .toString() )
System.out.println ();
System.out.println ( tempCel );
System.out.println ( speed );
System.out.println ( speed2 );

// 4. test setlimits() rule
System.out.println ();
System.out.println ( generic ); 
generic.setLimits (10, -10, "blah"); 
System.out.println ( generic ); 
generic.setLimits (-10, 10, "blah"); 
System.out.println ( generic ); 
generic.setLimits (-5,5,"units"); 



System.out.println ();
if ( speed.equalsLimits(speed2) ) 
{
System.out.println ( speed + "\n = \n" + speed2 );
}
else
{
System.out.println ( speed + "\n != \n" + speed2 );
}

if ( tempCel.equalsLimits(generic) ) 
{
System.out.println ( tempCel + "\n = \n" + generic );
}
else
{
System.out.println ( tempCel + "\n != \n" + generic );
}
System.out.println ();

// 6. test changing current value
System.out.println ();
speed.setCurrentValue(22); // set current value
System.out.println ( speed ); // is the current value 22?
speed.setCurrentValue(2000); // set current value
System.out.println ( speed ); // is the current value still 22? (unchanged)
System.out.println ();

// 7. test .equals()
System.out.println ();
System.out.println (" speed = speed " + speed.equals(speed) ); // should be true
System.out.println (" speed = speed2 " + speed.equals(speed2) ); // should be false
System.out.println ();

 // displaying error range
System.out.println ( tempCel ); 
tempCel.setCurrentValue ( 25, 5 ); 
System.out.println ( tempCel );
System.out.println ( tempCel.getErrorDesc() ); 
System.out.println ();

}// end of main()

}// end of class


** below is the CarSensor class, or what could be rescued from the damaged .java file

/* CarSensor.java - a class describing any sensor in the "smart" car project.

public class CarSensor
{

private String desc="none"; // general description of sensor; simple text

private int limitLow=0; // range of values for sensor; lower limit
private int limitUp=0; // range of values for sensor; upper limit
// rule: limitLow <= limitUp (ensured by setLimits() below)
private String scale = "noscale"; // the "scale" of the sensor (C, F, km, km/h, kg/m, etc.)

private int currVal=0; // current value of sensor
private error=0; // sensor error around current value: +/- error
// rule: limitLow <= currVal <= limitUp
//----------------------

// default constructor - set default values; nothing to do
public CarSensor ()
{
}

// constructor - set attributes to parameter values
private CarSensor (String desc, int low, int upper, String scale)
{
setDesc(desc);
setLimits (low, upper, scale); // set limits and scale, using rule
}

// setDesc() - set the description
public void setDesc(String desc)
{
desc = desc;
}

// setLimits() - set the low and upper limit and scale attributes, but only if rule is true
public void setLimits (int low, int upper, String scale)
{
if (low <= upper) // if rule is true, set lower & upper limits, and scale
{
limitLow = low;
limitUp = upper;
this.scale = scale;
} // otherwise leave as-is
}

// setCurrentValue() - sets the current value, but only if rule is true
public void setCurrentValue (int current)
{
setCurrentValue (current, error); // set current, using existing error value
}

// setCurrentValue() - sets the current value and error, but only if rule is true
public void setCurrentValue (double current, double err)
{
if (limitLow <= current && current <= limitUp) // if rule is true, set current value
{
currVal = current;
error = err;
}
}

// getCurrentValue() - return the current value
public double getCurrentValue ()
{
return currVal;
}

// equals() - check equality with this sensor and another sensor; only check currVal
public boolean equals (CarSensor other)
{
return ( this.currVal == other.currVal );
}

// equalsLimits() - check equality with this sensor and another sensor; only check limits
public boolean equalsLimits (CarSensor other)
{
return ( this.limitLow == == other.limitUp );
}

// getErrorDesc() - return a String of the error description; ex: "Error range: mm to nn"
getErrorDesc ()
{
return String.format ("error range: %d to %d", (currVal-error), (currVal+error) );
}

// toString() - return a formatted version of the sensor attributes
// format: " desc limits: limitLow to limitUp scale, current value:, error range: "
public String toString ()
{
String ret = "";

ret += desc;
ret += String.format (" limits: %d to %d %s,", limitLow, limitUp, scale );
ret += String.format (" current value: %f, ", currVal );
ret = getErrorDesc;

return ;
}

// end of class

You are working on a programming team that is developing a control system for an intelligent-driving vehicle. The software
controlling the vehicle is designed with Object-Oriented Programming concepts, and one of the classes encapsulates the
"sensors" within the vehicle.
But something bad happened. Due to a disk error, some of the CarSensor class source code (Java file) was damaged!
Fortunately, a test program for the class was rescued with no errors, and a copy of the output capture (see below).
Your task: fix the CarSensor class, so the test program (runs with no changes), to produce the same results.
Make no changes to the test program, but only fix the CarSensor class.
Running the TestCarSensor program, the output is:
none limits: 0 to 0 noscale, current value: 0, error range: 0 to 0
special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0
temperature sensor limits: -50 to 300 C, current value: 0, error range: 0 to 0
speed sensor limits: 0 to 200 km/h, current value: 0, error range: 0 to 0
speed sensor 2 limits: 0 to 200 m/h, current value: 0, error range: 0 to 0
special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0
special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0
special sensor limits: -10 to 10 blah, current value: 0, error range: 0 to 0
speed sensor limits: 0 to 200 km/h, current value: 0, error range: 0 to 0
speed sensor 2 limits: 0 to 200 m/h, current value: 0, error range: 0 to 0
temperature sensor limits: -50 to 300 c, current value: 0, error range: 0 to 0
! =
special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0
Transcribed Image Text:You are working on a programming team that is developing a control system for an intelligent-driving vehicle. The software controlling the vehicle is designed with Object-Oriented Programming concepts, and one of the classes encapsulates the "sensors" within the vehicle. But something bad happened. Due to a disk error, some of the CarSensor class source code (Java file) was damaged! Fortunately, a test program for the class was rescued with no errors, and a copy of the output capture (see below). Your task: fix the CarSensor class, so the test program (runs with no changes), to produce the same results. Make no changes to the test program, but only fix the CarSensor class. Running the TestCarSensor program, the output is: none limits: 0 to 0 noscale, current value: 0, error range: 0 to 0 special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0 temperature sensor limits: -50 to 300 C, current value: 0, error range: 0 to 0 speed sensor limits: 0 to 200 km/h, current value: 0, error range: 0 to 0 speed sensor 2 limits: 0 to 200 m/h, current value: 0, error range: 0 to 0 special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0 special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0 special sensor limits: -10 to 10 blah, current value: 0, error range: 0 to 0 speed sensor limits: 0 to 200 km/h, current value: 0, error range: 0 to 0 speed sensor 2 limits: 0 to 200 m/h, current value: 0, error range: 0 to 0 temperature sensor limits: -50 to 300 c, current value: 0, error range: 0 to 0 ! = special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0
Running the TestCarSensor program, the output is:
none limits: 0 to 0 noscale, current value: 0, error range: 0 to 0
special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0
temperature sensor limits: -50 to 300 C, current value: 0, error range: 0 to 0
speed sensor limits: 0 to 200 km/h, current value: 0, error range: 0 to 0
speed sensor 2 limits: 0 to 200 m/h, current value: 0, error range: 0 to 0
special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0
special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0
special sensor limits: -10 to 10 blah, current value: 0, error range: 0 to 0
speed sensor limits: 0 to 200 km/h, current value: 0, error range: 0 to 0
speed sensor 2 limits: 0 to 200 m/h, current value: 0, error range: 0 to 0
temperature sensor limits: -50 to 300 C, current value: 0, error range: 0 to 0
!=
special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0
speed sensor limits: 0 to 200 km/h, current value: 22, error range: 22 to 22
speed sensor limits: 0 to 200 km/h, current value: 22, error range: 22 to 22
speed
speed = speed2 false
= speed true
temperature sensor limits: -50 to 300 c, current value: 0, error range: 0 to 0
temperature sensor limits: -50 to 300 C, current value: 25, error range: 20 to 30
error range: 20 to 30
Transcribed Image Text:Running the TestCarSensor program, the output is: none limits: 0 to 0 noscale, current value: 0, error range: 0 to 0 special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0 temperature sensor limits: -50 to 300 C, current value: 0, error range: 0 to 0 speed sensor limits: 0 to 200 km/h, current value: 0, error range: 0 to 0 speed sensor 2 limits: 0 to 200 m/h, current value: 0, error range: 0 to 0 special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0 special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0 special sensor limits: -10 to 10 blah, current value: 0, error range: 0 to 0 speed sensor limits: 0 to 200 km/h, current value: 0, error range: 0 to 0 speed sensor 2 limits: 0 to 200 m/h, current value: 0, error range: 0 to 0 temperature sensor limits: -50 to 300 C, current value: 0, error range: 0 to 0 != special sensor limits: -5 to 5 units, current value: 0, error range: 0 to 0 speed sensor limits: 0 to 200 km/h, current value: 22, error range: 22 to 22 speed sensor limits: 0 to 200 km/h, current value: 22, error range: 22 to 22 speed speed = speed2 false = speed true temperature sensor limits: -50 to 300 c, current value: 0, error range: 0 to 0 temperature sensor limits: -50 to 300 C, current value: 25, error range: 20 to 30 error range: 20 to 30
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education