Okay. I am very new to Java and I am very excited about it. However, I have hit a brick wall. I have a couple of questions about my code.
How can I make the program print a blank space in between the ****RESIDENTIAL ....***** and Max number of customers....?
I want the program to say at the end - Cost for residential customer 1: is $ ---- then customer 2: is $ ------then customer 3: is $..... -----My code is only saying that "Gas used by residential customer 4444" This is just an example. I hope I made this question clear.
Here is the first part of my code that will compile but I have the problems above:
import java.io.*;
import java.text.DecimalFormat;
public class lab5
{
public static void main(String[] args)
{
int resAmounts = 0;
int busAmounts = 0;
double resCosts = 0;
double busCosts = 0;
int[] resAmount = new int[20]; // Cubic meters - residential
int[] busAmount = new int[20]; // Cubic meters - business
int[] planNumber = new int[20]; // Plan numbers - business
double[] resCost = new double[20]; // Residential costs
double[] busCost = new double[20]; // Business costs
System.out.println("*******RESIDENTIAL CUSTOMER ACCOUNTS*******");
int numCust = inputNumCust(); // Call to get number of customers
getResAmounts(numCust, resAmount); // Call to get Residential amounts
getResCosts(numCust, resAmount, resCost); // Call to get Residential costs
System.out.println("Cost for Residential customer " + numCust + " " + ": is" + resCosts[j]);
} // End of Main
public static int inputNumCust()
{
int max = 20, numCust = 0;
System.out.println("Max number of customers allowed is " + max);
do
{
System.out.println("Enter number of customers:");
numCust = MyInput.readInt();
}while(numCust > 20);
System.out.println("Number of customers read as: " + numCust);
return (numCust);
} // End of InputNumCust
public static void getResAmounts(int numCust, int [] resAmount)
{
System.out.println("......Natural Gas Residential Usage........");
for(int i = 0; i < numCust; i++)
{
{
System.out.println("Enter meter reading for previous month (less than 9999):");
int starting = MyInput.readInt();
System.out.println("Enter meter reading for current month (less than 9999):");
int ending = MyInput.readInt();
resAmount[i] = ending - starting;
if (resAmount[i] < 0)
{
resAmount[i] = 10000 - starting + ending;
}
System.out.println("Gas used (cubic meters) by Residential customer " + numCust() + " " + resAmount[i] + " ");
}
}
}
Now here is the part of my code that will not compile::: Please help with this! Please!
public static void getResCosts(int numCust, int [] resAmount, double [] resCost)
{
System.out.println("......Natural Gas Residential Costs........");
for(int j = 0; j < numCust; j++)
{
if (resAmount[] <= 70)
{
resCost[j] = 5.00;
}
else if ((resAmount[] > 70) && (resAmount[i] <= 170))
{
resAmount[] = resAmount[] - 70;
resCost[j] = 5.00 + (resAmount[] * .05);
}
else if ((resAmount[] > 170) && (resAmount[] <= 400))
{
resAmount[] = resAmount[i] - 170;
resCost[j] = 10.00 + (resAmount[] * .025);
}
else
{
resAmount[] = resAmount[] - 400;
resCost[j] = 15.75 + (resAmount[] * .015);
}
System.out.println("Cost for Residential customer numCust() is " + resCost);
}
}
} // End of Class
Any help?
Thank you in advance