2)Given Slope java to the right, in the main method below, write code with the f
ID: 3804929 • Letter: 2
Question
2)Given Slope java to the right, in the main method below, write code with the following requirements. A) Declare a variable named s and assign it a new instance of the slope class. If an argument is needed, pick any you'd like. B) Without using a loop, call methods on the Slope object from (A such that its position field will ultimately hold a value of 173 before moving to (c) Using console, print the value returned by calling the Slope object's getPosition method public static void main(stringl] args) console console new consoleo public class slope private int position; private boolean slippery; public slope (boolean slippery) -slippery slippery -position e; public void go() if slippery) -position position 60; else t -position position 2 public void reverse() if slippery) -position position 10; else -position position 1; public void setslippery (boolean s) slippery s; public int getPosition() return position; Page 2 of 2Explanation / Answer
This is a main class of your code,actually The Console class is obviously not meant to be instantiated directly. You are supposed to use System.console instead of new ,because Console is built in java class,and The Java Console class is be used to get input from console.Here in our program we are not take any input so we will only check the program is run on console or not.
public static void main(String args[])
{
Console console= System.console();
Slope s = new Slope(true);
Slope s1=new Slope(false);
int i1 = 2*s.go();
int i2 = s.reverse();
int j = 2 * s1.go();
int j2 = s1.reverse();
int z=i1 + i2 + (j-j2);
System.out.println(s.get_position());
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.