Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
So basically im trying to figure out how to get a gross revenue for the week for this program, but don't know how. Someone had told me that i was supposed to do it like how i have it in my code, but that obviously doesn't work. How do i loop this properly and get the gross revenue?



C#
import javax.swing.JOptionPane;

public class Exam2MAY
{
    public static void main(String[] args)

    {
        String productName;
        String modelNum;
        String productPrice;
        String productQuantity;
        String differentProducts;

        int loopCount = 0;
        int grossRevenueAll;

        differentProducts = JOptionPane.showInputDialog(null,"How many products will you enter? (Keep under 5)");

        do
        {
        productName = JOptionPane.showInputDialog(null,"Enter the name of the product.");
        modelNum = JOptionPane.showInputDialog(null,"What is the model number?");
        productPrice = JOptionPane.showInputDialog(null,"What is the price of the product? $");
        productQuantity = JOptionPane.showInputDialog(null,"What is the quantity of sold product this week");

        int otherProducts = Integer.parseInt(differentProducts);
        double price = Double.parseDouble(productPrice);
        double quantity = Double.parseDouble(productQuantity);
        double grossPrice = price * quantity;
        loopCount = otherProducts;


        System.out.println("Product name :" + productName);
        System.out.println("Model number :" + modelNum);
        System.out.println("Product price :" + productName);
        System.out.println("Product quantity :" + productQuantity);
        System.out.println("Gross revenue : $" + grossPrice);
        ++ loop;
        grossRevenueAll(loop) = price;
        }
        while(loopCount < 5);
        System.exit(0);
        int currentProduct = loopCount;
    }
}



There's the code :P
Posted

1 solution

The simplest way to do it would be to calculate the gross revenue for each item after it is entered, and add this to a totalGrossRevenue field (which you would initialise to zero)

Essentially where you have

grossRevenueAll(loop) = price

which doesn't make sense to me!

you would habe

grossRevenueAll += grossPrice.

Just some tips, while I am here...

Call your variables what they are - you have a grossPrice variable representing grossRevenue - why not call it grossRevenue?

Indent your loop - it makes it easier to see what's going on.

You've got 'while (loopCount < 5) - I think this should be < differentProducts?

You've got ++loop - I don't see a variable called loop so imagine this doesn't compile - and you don't appear to use it anyway?

Good luck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900