There are 100 closed lockers in a school. There are 100 students outside the sch
ID: 3638331 • Letter: T
Question
There are 100 closed lockers in a school. There are 100 students outside the school. The first student goes into the school and visits every locker and opens it. The second student goes into the school and closes every locker that is a multiple of two. The third student goes into the school and visits every locker that is a multiple of three. If the locker is open he/she closes it, if the locker is closed he/she opens it. The fourth student goes into the school and visits every locker that is a multiple of four. Again if the locker is open he/she closes it, if the locker is closed he/she opens it. This continues until all 100 students have gone into the school and gone to the appropriate lockers.Write a program that will determine and display the status of each locker after all of the students have gone into the school.
1. Output a list of all the open lockers.
2. If each student who goes into the school places a quarter into each locker he/she visits, which locker will have the most money deposited into it?
3. What is the total amount of money that will be placed into all of the lockers?
--------------------------------------------------------------------------------------------------
//This is the method/ class I have created, I need to create another class where I
//carry out this method and get the answers to the questions above.
class Locker
{
private boolean open;
private double money;
public Locker()
{
open = false;
money = 0.0;
}
public void visit()
{
if (open)
open = false;
else
open = true;
money +=.25;
}
public double getMoney()
{
return money;
}
public boolean isOpen()
{
return open;
}
public String toString()
{
String out = "";
if (open)
out += " open ";
else out += " closed ";
out += "with $" + money + " inside";
return out;
}
}
--------------------------------------------------------------------------
//I started some of this, need help with completion and correction:
public class lockers2
{
public static void main(String[] arg)
{
Locker[]lockers=new Locker[100];
for(int i = 1; i < lockers.length; i++)
{
for(int j = 2; j < lockers.length; j += 2)
{
lockers[i]= new Locker();
lockers[i].visit();