Question
in Java Write a class RangeInput that allows users to enter a value within a range of values that is provided in the constructor. An
in Java
Write a class RangeInput that allows users to enter a value within a range of values that is provided in the constructor. An example would be a temperature control switch in a car that allows inputs between 60 and 80 degrees Fahrenheit. The input control has up and down buttons. Provide up and down methods to change the current value. The initial value is the midpoint between the limits. As with the preceding exercises, use Math.min and Math.max to limit the value. Write a sample program that simulates clicks on controls for the passenger and driver seats.
RangeInput.java can be edited
Public class RangeInput{
private int currentValue;
private int highValue;
private int lowValue;
// have to assign lowValue and highValue to and argument and CurrentValue to a midpoint that would calculate lowValue and highValue and divide by 2
public Range Input (int low, int high){
//this is the constructor
}
// Need to write code that will increase current value by 1 but also remain within range of input values..
public void up(){
//this is a mutator method
// that increases currentValue if allowed
// need to use Math.min to compare and get the smallest value of the two values being compared
}
// this part of the code need to be the opposite of the previous we need to decrease the value but also remain in range of the input values.
public void down(){
//this is a mutator method
//that decreases currentValue if allowed
// need to use Math.max to get the highest value of the two values being compared.
}
//this part of the code would need to allow for a retrieval of the current value on the range.
public int getCurrentValue(){
// this is an accessor method
//your code here
}
}
RangeInputTester.java- Dont change CODE
public class RangeInpuTester{
public static void main(String[] args){
RangeInput myInput = new RangeInput (40,50);
System.out.println(current value: + myInput.getCurrentValue());
for (int i = 0; i < 4; i ++){
myInput.up();
}
System.out.println(last value: + myInput.getCurrentValue());
}
}
public class RangeInput {
private int minValue;
private int maxValue;
private int currentValue;
public RangeInput(int minValue, int maxValue) {
this.minValue = minValue;
this.maxValue = maxValue;
this.currentValue = (minValue + maxValue) / 2;
}
public void up() {
currentValue = Math.min(currentValue + 1, maxValue);
}
public void down() {
currentValue = Math.max(currentValue - 1, minValue);
}
public int getCurrentValue() {
return currentValue;
}
}
can you test code before submitting answer so that no errors pop up in terminal. please do not answer if you cannot provide solution
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