Is there any way in Java to reset my accumulator to zero after I get all of my user data in my first go around in my loop and have it displayed. Here is a short posting of my code. After my first nursing home I want my accumulator to be zero for my next nursing home data. My accumulators are collecting all user data for my total rooms and total occupied rooms when I want it split up between nursing homes.
<public class project3DemoMorris
{
public static void main(String[] args)
{
int buildNum; //number of buildings
int floorNum; //number of floors
int roomFloor; //number of rooms per floor
int occupiedRooms; //number of occupied rooms
int floorsCount;
int totalRooms;
int totaloccupiedRooms;
//Display the heading of our program
displayMessage();
//Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(System.in);
DecimalFormat formatter = new DecimalFormat ("#0%");
totalRooms=0;
totaloccupiedRooms=0;
//Get the number of buildings
System.out.println("Enter the number of buildings");
buildNum = keyboard.nextInt();
while (buildNum<=0)
{
System.out.println("Invalid entry: Number of buildings must be greater than 0.");
System.out.print("Reenter the number of buildings:");
buildNum = keyboard.nextInt();
}
for (int buildingCount = 1; buildingCount <= buildNum; buildingCount++)
{
System.out.print("How many floors are in the nursing home " + buildingCount +"?: ");
floorNum = keyboard.nextInt();
while (floorNum<=0)
{
System.out.println("Invalid entry: Floors must be greater than 0.");
System.out.print("Reenter the number of floors in nursing home " + buildingCount +":");
floorNum = keyboard.nextInt();
}
for (floorsCount = 1; floorsCount<=floorNum; floorsCount++)
{
System.out.print("How many rooms does floor" + floorsCount+"?: ");
roomFloor = keyboard.nextInt();
while (roomFloor<10)
{
System.out.println("Invalid entry: Rooms cannot be less than 10.");
System.out.print("Reenter the number of Rooms.");
roomFloor = keyboard.nextInt();
}
totalRooms+=roomFloor;
System.out.print("How many occupied rooms are on the floor?: ");
occupiedRooms = keyboard.nextInt();
while (occupiedRooms<=0)
{
System.out.println("Invalid entry: Occupied rooms must be 0 or greater.");
System.out.println("Reenter number of occupied rooms on the floor.");
occupiedRooms = keyboard.nextInt();
}
totaloccupiedRooms+=occupiedRooms;
// System.out.println(totaloccupiedRooms);
//System.out.println(totalRooms);
//Create an instance of project3Morris
//passing the data that was entered as arguments
//to the constructor
project3Morris number = new project3Morris(buildNum, floorNum, roomFloor, occupiedRooms, floorsCount,totaloccupiedRooms, totalRooms );
//Get the data from number and display it
totalRooms=0;
totaloccupiedRooms=0;
System.out.println ("Nursing Home:" + number.getNumBuildings());
System.out.println ("Total Number Of Rooms:" + number.getTotalRooms());
System.out.println ("Total Occupied Rooms:" + number.getTotalOccupiedRooms());
System.out.println ("Total Vacant Rooms:" + number.getVacantRooms());
System.out.println ("Occupancy Rate:" + formatter.format
(number.getOccupancyRate()));
if (number.getOccupancyRate()>=.75)
System.out.println("Occupancy Rate is High");
else if (number.getOccupancyRate()>=.50 && number.getOccupancyRate()<=.74)
System.out.println("Occupancy Rate is Average");
else if (number.getOccupancyRate()<.50)
System.out.println("Occupancy Rate is Low");
}
}
}
//Creating a method for the heading of our program
public static void displayMessage()
{
System.out.println("This is the Sunshine Nursing Home Program:");>
}
}