Why doesn't this code let me run it. I just finished it really...
public class ComboLock { int secret1, secret2, secret3; // secret keys int dial1, dial2, dial3; // variables used to store dialed ticks boolean first, second, third; // variables used to store current turn number(how many numbers entered already) public ComboLock(int secret1, int secret2, int secret3) { super(); this.secret1 = secret1; this.secret2 = secret2; this.secret3 = secret3; this.dial1 = 0; this.dial2 = 0; this.dial3 = 0; this.first = false; this.second = false; this.third = false; // constructor } public void reset(){ this.dial1 = 0; this.dial2 = 0; this.dial3 = 0; this.first = false; this.second = false; this.third = false; // method to rest dials to zero } public void turnLeft(int ticks){ if(first){ this.dial2 = (this.dial1 - ticks)%40; this.second = true; // when turning left will take place then user may be entering second number, // if user already moves to left in first attempt then second variable will // not set to true and open will return false as it should be // it only works when user already entered the first number } } public void turnRight(int ticks){ if(!first){ this.dial1 = ticks%40; this.first = true; } else{ this.dial3 = (this.dial2 + ticks)%40; this.third = true; } } public boolean open(){ if(this.first && this.second && this.third && this.dial1==this.secret1 && this.dial2==this.secret2 && this.dial3==this.secret3){ return true; } return false; // check if all numbers are entered and are correct then open the lock else deny } public static void main(){ ComboLock lock = new ComboLock(15, 35, 20); lock.turnRight(15); lock.turnLeft(20); lock.turnRight(25); System.out.println(lock.open()); lock.reset(); lock.turnRight(15); lock.turnLeft(20); lock.turnRight(24); System.out.println(lock.open()); } }
Explanation:
In JAVA main method is written as
public static void main(String[] args){
// Main function body
}
And in your code String[] args is missing from main() method parameter.
Output of your code is:
false
false
Please give feedback!
Thank You!!
Why doesn't this code let me run it. I just finished it really... public class ComboLock...
Code in blue j. A tester class is needed. Also if you comment that will help greatly. If you can help me I will give you a thumbs up. Declare a class ComboLock that works like the combination lock in a gym locker, as shown below. The lock is constructed with a combination—three numbers between 0 and 39. The reset method resets the dial so that it points to 0. The turnLeft and turnRight methods turn the dial by a...
Java Help, Will definitely give a thumbs up if it works. Declare a class ComboLock that works like the combination lock in a gym locker (Consult the API provided to look for the methods needed). The locker is constructed with a combination - three numbers between 0 and 39. The reset method resets the dial so that it points to 0. The turnLeft and turnRight methods turn the dial by a given number of ticks to the left or right....
java problem here is the combination class class Combination { int first,second,third, fourth; public Combination(int first, int second, int third,int fourth) { this.first=first; this.second=second; this.third=third; this.fourth=fourth; } public boolean equals(Combination other) { if ((this.first==other.first) && (this.second==other.second) && (this.third==other.third) && (this.fourth==other.fourth)) return true; else return false; } public String toString() { ...
Declare a class ComboLock that works like the combination lock in a school or gym locker.. The lock is constructed with a combination dial numbers between 0 and 39. The constructor sets the three "secret" numbers and the current position to 0. The reset method resets the dial so that it points to 0. The turnLeft and turnRight methods turn the dial by a given number of ticks to the left or right. The open method attempts to open the...
Hello, i need help with this homework: Code provided: public class DirectedWeightedExampleSlide18 { public static void main(String[] args) { int currentVertex, userChoice; Scanner input = new Scanner(System.in); // create graph using your WeightedGraph based on author's Graph WeightedGraph myGraph = new WeightedGraph(4); // add labels myGraph.setLabel(0,"Spot zero"); myGraph.setLabel(1,"Spot one"); myGraph.setLabel(2,"Spot two"); myGraph.setLabel(3,"Spot three"); // Add each edge (this directed Graph has 5 edges, // so we add 5 edges) myGraph.addEdge(0,2,9); myGraph.addEdge(1,0,7); myGraph.addEdge(2,3,12); myGraph.addEdge(3,0,15); myGraph.addEdge(3,1,6); // let's pretend we are on...
Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp { public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...
SIMPLE: PSEUDOCODE FOR THE CODE BELOW Bingo.java package bingo; import java.util.Scanner; import java.util.Random; public class Bingo { public static BingoCard gameCard; public static int totalGamesWon = 0; public static void main(String[] args) { //Use do-while loop to do the following: //1. instantiate a gameCard //2. call the method playGame() //3. call the method determineWinner() //4. Ask user if they wish to play again? (1 = yes; 2 = no)...
Explain in detail what the code below does: public class MyClass { public static void main(String args[]) { System.out.println(isUniqueChars("something")); } public static boolean isUniqueChars(String str) { int checker = 0; for (int i = 0; i < str.length(); ++i) { int val = str.charAt(i) - 'a'; if ((checker & (1 << val)) > 0) return false; checker |= (1 << val); } return true;...
Modify the Triangle class (from previous code, will post under this) to throw an exception in the constructor and set routines if the triangle is not valid (i.e., does not satisfy the triangle inequality). Modify the main routine to prompt the user for the sides of the triangle and to catch the exception and re-prompt the user for valid triangle sides. In addition, for any valid triangle supply a method to compute and display the area of the triangle using...
Write Junit Test for the following class below: public class Turn { private int turnScore; private Dice dice; private boolean isSkunk; private boolean isDoubleSkunk; public Turn() { dice = new Dice(); } public Turn(Dice dice) { this.dice = dice; } public void turnRoll() { dice.roll(); if (dice.getDie1Value() == 1 || dice.getDie2Value() == 1 && dice.getLastRoll() != 2) { turnScore = 0; isSkunk = true; } else if (dice.getLastRoll() == 2) { turnScore = 0; isDoubleSkunk = true; } else { ...