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()
{
return
first+":"+second+":"+third+":"+fourth;
}
}
public class CombinationEx
{
public static void main(String args[])
{
Combination c1=new
Combination(1,2,3,4);
Combination c2=new Combination
(1,2,3,4);
Combination c3=new
Combination(4,5,6,7);
boolean r1=c1.equals(c2);
System.out.println( "c1 equals c2
"+ r1);
boolean r2=c1.equals(c3);
System.out.println("c1 equals c3
"+r2);
System.out.println(c1);
System.out.println(c3);
}
}
Thanks for the question.
Here is the completed code for this problem. Let me know if you have any doubts or if you need anything to change.
Thank You !!
================================================================================================
public class DoorLock {
public static final int MAX_NUMBER_OF_ATTEMPTS = 6;
private Combination combination;
private boolean isOpen;
private boolean isEnabled;
private int failedAttempts;
public DoorLock(Combination combination) {
this.combination = combination;
isOpen = false;
isEnabled = true;
failedAttempts = 0;
}
public boolean isOpen() {
return isOpen;
}
public boolean isEnabled() {
return isEnabled;
}
public void enable(Combination c) {
if (combination.first == c.first && combination.second == c.second &&
combination.third == c.third && combination.fourth == c.fourth) {
isEnabled = true;
}
}
public boolean open(Combination c) {
if (isEnabled) {
if (combination.first == c.first && combination.second == c.second &&
combination.third == c.third && combination.fourth == c.fourth) {
isOpen = true;
failedAttempts = 0;
return true;
} else {
failedAttempts++;
if (failedAttempts == MAX_NUMBER_OF_ATTEMPTS) {
isEnabled = false;
}
}
}
return false;
}
}
========================================================================================
java problem here is the combination class class Combination { int first,second,third, fourth; public...
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 =...
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...
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....
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...
Need help debugging. first class seems fine. second class is shooting an error on s = super.getString(prompt); third class is giving me an error in the while loop where int num = console.getInt("Enter an integer:"); //-------------------------------------------------------------------------- import java.util.Scanner; public class Console { private Scanner sc; boolean isValid; int i; double d; public Console() { sc = new Scanner(System.in); } public String getString(String prompt) { System.out.print(prompt); return sc.nextLine();...
Assignment (to be done in Java):
Person Class:
public class Person extends Passenger{
private int numOffspring;
public Person() {
this.numOffspring = 0;
}
public Person (int numOffspring) {
this.numOffspring = numOffspring;
}
public Person(String name, int birthYear, double weight, double
height, char gender, int numCarryOn, int numOffspring)
{
super(name, birthYear, weight, height, gender,
numCarryOn);
if(numOffspring < 0) {
this.numOffspring = 0;
}
this.numOffspring = numOffspring;
}
public int getNumOffspring() {
...
Java Time Class Class declarations are one of the ways of defining new types in Java. we will create two classes that both represent time values for a 24 hours period. The valid operations are as follows. int getHours(): returns the number of hours int getMinutes(): returns the number of minutes int getSeconds(): returns the number of seconds String toString(): returns a String representation boolean equals(Time other): returns true if and only if other designates an object that has the...
public class Lock{ // ADD ATTRIBUTES HERE /** Create a lock for the specified box * <p> * The lock must be initially locked (closed) when created. * The lock must be given a UNIQUE ID value when created. * * @param box is a Box that will have this lock to keep is shut. */ public Lock(Box box){} /** Retrieve the key for this lock. * <p> * This method can be called multiple times but is only allowed...
In java Build a QueueInt class for integers that is compatible with the driver code below. The QueueInt should operate in a FIFO (first in, first out) fashion and implement the variables and methods also listed below: Data Members: Declare and initialize, as needed, the data item(s) you will need to manage a queue of integers. You may only use arrays and primitives for your instance and/or static variables (I,e You can’t use Java defined Queue / Stack / List...
use java follow my code: public class q1 { // Instance Variables int currentFloor; double maximumWeight; int topFloor; // Constructor Declaration of Class public q1 (int currentFloor, double maximumWeight, int topFloor) { this.currentFloor = currentFloor; this.maximumWeight = maximumWeight; this.topFloor = topFloor; } // Property to get value of currentFloor instance variable public int getCurrentFloor() { return currentFloor; } // Property...