1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
faust18 [17]
3 years ago
11

Write a JAVA program that simulates a circuit for controlling a hallway light that has switches at both ends of the hallway. Eac

h switch can be up or down, and the light can be on or off. Toggling each switch turns the light on or off. (This is called a 3-way switch).
Create a class called ThreeWaySwitch which simulates this situation. Provide two instance variables for the states of the two switches at each end of the hallway:

private int firstSwitchState = 0,
secondSwitchState= 0 ;
Provide a constructor with the following heading:

public ThreeWaySwitch(int initialFirstSwitch,
int initialSecondSwitch)
and the following methods:

public int getFirstSwitchState() // 0 = down, 1 = up
public int getSecondSwitchState()
public int getLightState() // 0 = off, 1 = on
public void toggleFirstSwitch()
public void toggleSecondSwitch()
Do not:

provide a third instance variable for the light's state (on or off)
use the ternary operator '?', or any if or switch statements in this class
instead use the '+' and '%' operators (hint: (1 + 1) % 2 = 0)
Write a class named CircuitTester that tests all four switch combinations, printing the status of the two switches and the light for each combination of switches (down/down, up/down, down/up, and up/up).
Computers and Technology
1 answer:
cupoosta [38]3 years ago
5 0
I used to study this but I forgot how
You might be interested in
Your program will read a word (or a whole line) from the user. It will then count the number of vowels in the word (or line) and
Softa [21]

Answer:

Following are the program in the Python Programming Language.

def vowel(): #define function

 print("Enter END to Break") #print message

 while(True): #set while loop

   word=input("Enter words: ") #get input from the user

   count=0 #set count to 0

   if(word=="END"): #set if condition

     break #terminate the loop

   else:

     for i in range(len(word)): #set the for loop

       c=word[i] #initialize in c

       if(c=='a'or c=='e' or c=='i'or c=='o'or c=='u'or c=='A'or c=='E'or c=='I'or c=='O'or c=='U'):

         count+=1 #increament in count by 1

     print("The word " , word , " contains " , count, end=" ")#print message

     if(count==1):#check condition

       print("vowel.")

     else:

       print("vowels")

#call the function

vowel()

Output:

Enter END to Break

Enter words: Vowel

The word  Vowel  contains  2 vowels

Enter words: END

Explanation:

Here, we define a function "vowel()" inside it.

  • Print message for the user.
  • Set the while loop and pass condition is True then, get input from the user in the variable "word" then, set variable "count" and initialize to 0.
  • Set if condition to check if the user input "END" then, the loop will terminate.
  • Otherwise, set for loop which continues from the length of the word.
  • Then, we set if statement which checks the vowel in the word, then increment in count by 1.
  • Print the message in the following format which is mentioned in the question.
  • Then, set if-else statement for check count is equal to 1 then print "vowel." Otherwise, it prints "vowels."

Finally, we call the following function "vowel()".

4 0
3 years ago
The duties of a database administrator include determining which people have access to what kinds of data in the database; these
fomenos

Answer:

Processing Rights.

Explanation:

The duties of a database administrator include determining which people have access to what kinds of data in the database; these are referred to as processing rights. There are other kind of rights too that will be decided by the Database Administrator. The database administrator grants access to different people depending on the usages of the database. There can be different types of data in the database. These are called the Processing rights.

7 0
3 years ago
Read 2 more answers
Mechanisms that can be used to rescue accident victims
stiks02 [169]

Answer:

Hydraulic rescue tools

6 0
2 years ago
Name three technologies that begin with the same letter of the alphabet
qaws [65]
Active-Matrix 
Applet
ATM
8 0
4 years ago
Read 2 more answers
How are computers classified into different types? Explain ​
zloy xaker [14]

Answer:

On the basis of size there are four types of computer. They are minicomputer, micro computer, mainframe computer and super computer. Super computer is the fastest, most expensive, big in size, and most powerful computer that can perform multiple tasks within no second.

3 0
2 years ago
Other questions:
  • Which button could Pamela press in the Microsoft Word spell checker to make the word “colour” instantly change to “color” whenev
    11·1 answer
  • list the sixth external parts of a computer system and identify which are output and which are input devices
    14·2 answers
  • In cell e9, enter a formula that calculates the session fee for a member. members receive a member discount off the non-member s
    9·1 answer
  • 3. Which one of the following statements is true for spell checkers?
    11·1 answer
  • Briefly describe the software quality dilemma in your own words
    13·1 answer
  • In remote areas,your gps device may lose reception. its good idea to have a
    13·1 answer
  • In what situation is a read receipt notification not sent when an email is opened or previewed bya recipient?
    8·2 answers
  • Sixteen stations, numbered 1 through 16, are contending for the use of a shared channel by using the adaptive tree walk protocol
    7·1 answer
  • Nick is moving from Alabama to Texas. A friend of his remarked that Nick may have to pay higher taxes there. What is the cheapes
    7·1 answer
  • Is pseudocode obtained from Algorithm or is Algorithm obtained from pseudocode?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!