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.

  1. How can I make the program print a blank space in between the ****RESIDENTIAL ....***** and Max number of customers....?

  2. 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

1. How can I make the program print a blank space in between the ****RESIDENTIAL ....***** and Max number of customers....?

At present the output should be like this
*****Residential.......**********
Max number of customers...........
rt?
you want it in the same line is it instead of a new line

instead of using println which prints in a new line use print in the print statement for max no of customers and add " "

2) System.out.println("Cost for Residential customer " + numCust + " " + ": is" + resCosts[j]);
this is written inside the main.
how will the program get the value of numCust and j.
put it in a loop
for(j=0;j<numcust;j++)
{
System.out.println("Cost for Residential customer " + numCust + " " + ": is" + resCosts[j]);
}

3) resAmount[] <= 70

everywhere you have used resAmount[] like this try adding j that is use resAmount[j] instead.

i dont have java installed so could not make the changes and try out.
this should do.....
just post here if it does not

Okay, here is my complete code...It still is giving me compile errors in the getResCosts method:

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]);
        System.out.println("******BUSINESS CUSTOMER ACCOUNTS******");
        numCust = inputNumCust(); // Call to get Business amounts
        getBusAmounts(numCust, planNumber, busAmount);
        getBusCosts(numCust, planNumber, busAmount, busCost);
        System.out.println("Cost for Business customer " + numCust + " " + ": is" + busCosts[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] + " ");
        }
    }

    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[j] <= 70)
            {
                resCost[j] = 5.00;
            }
            else if ((resAmount[j] > 70) && (resAmount[j] <= 170))
            {
                resAmount[j] = resAmount[j] - 70;
                resCost[j] = 5.00 + (resAmount[j] * .05);
            }
            else if ((resAmount[j] > 170) && (resAmount[j] <= 400))
            {
                resAmount[j] = resAmount[j] - 170;
                resCost[j] = 10.00 + (resAmount[j] * .025);
            }
            else
            {
                resAmount[j] = resAmount[j] - 400;
                resCost[j] = 15.75 + (resAmount[j] * .015);
            }
            System.out.println("Cost for Residential customer numCust() is " + resCost(j) + " ");
        }
    }

    public static void getBusAmounts(int numCust, int [] planNumber, int [] busAmount)
    {
        System.out.println(".....NATURAL GAS BUSINESS USAGE .....");
        System.out.println("PLAN 1 - FOR LOW VOLUME USERS");
        System.out.println("PLAN 2 - FOR MEDIUM VOLUME USERS");
        System.out.println("PLAN 3 - FOR LARGE VOLUME USERS");
        System.out.println("PLAN 4 - FOR HIGHEST VOLUME USERS");
        for(int k = 0; k < numCust; k++)
        {
            System.out.println("Enter the plan number for customer :");
            int plan = MyInput.readInt();
            while ((plan < 1) || (plan > 4))
            {
                System.out.println("PLAN NUMBER ERRROR...PLEASE ENTER EITHER 1 OR 2 OR 3 OR 4");
                System.out.println("...NATURAL GAS BUSINESS USAGE PLANS...");
                System.out.println("PLAN 1 - FOR LOW VOLUME USERS");
                System.out.println("PLAN 2 - FOR MEDIUM VOLUME USERS");
                System.out.println("PLAN 3 - FOR LARGE VOLUME USERS");
                System.out.println("PLAN 4 - FOR HIGHEST VOLUME USERS");
                System.out.println("Enter the plan number:");
                plan = MyInput.readInt();
            }
            System.out.println("Enter meter reading for previous month (less than 9999):");
            int previous = MyInput.readInt();
            System.out.println("Enter meter reading for current month (less than 9999):");
            int current = MyInput.readInt();
            int amount = current - previous;
            if (amount < 0)
            {
                amount = 10000 - previous + current;
            }
            System.out.println("Gas used (cubic meters) by Business customer " + numCust() + " " + resAmount[i] + " ");
        }
    }

    public static void getBusCosts(int numCust, int [] planNumber, int [] busAmount, double [] busCost)
    {
        System.out.println("......Natural Gas Business Costs........");
        switch (planNumber)
        {
            case 1:
                cost = 200 + (.04 * amount);
                System.out.println("Cost is $" + cost);
                break;
            case 2:
                cost = 300 + (.035 * amount);
                System.out.println("Cost is $" + cost);
                break;
            case 3:
                cost = 350 + (.029 * amount);
                System.out.println("Cost is $" + cost);
                break;
            case 4:
                cost = 400 + (.024 * amount);
                System.out.println("Cost is $" + cost);
                break;
        }
    }

} // End of Class

Any help at all? Thank you.

I'd bet the compile error is this:

System.out.println("Cost for Residential customer numCust() is " + resCost(j) + " ");

it should be:

System.out.println("Cost for Residential customer numCust() is " + resCost[j] + " ");

because resCost is an array.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.