Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Total Sales Error

  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Total Sales Error

    Here are the instructions:
    Use a two-dimensional array to solve the following problem:

    A company has four salespeople (1 to 4) who sell five different products (1 to 5). Once a day, each salesperson passes in a slip for each type of product sold. Each slip contains the following:

    a) The salesperson number (1 to 4)
    b) The product number
    c) The total dollar value of the product (1 to 5) sold that day

    Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all the slips for last month is available. Write an application that will read all this information for last month's sales and summarize the total sales by salesperson and by product. All totals should be stored in the two-dimensional array sales.

    After processing all the information for a month (all the records in the data file), display the results in tabular format, with each column representing a particular salesperson and each row representing a particular product. Cross-total each row to get the total sales of each product for the month. Cross-total each column to get the total sales by salesperson for the month. Your tabular output should include these cross-totals to the right of the totaled rows and to the bottom of the totaled columns.

    Then my code is: but doesn't seem to work.


    public class TotalSales
    {
    private String courseName;
    private int sales[];
     
    public TotalSales (String name, int salesArray[] )
    {
     
    	courseName =name;
    	sales = salesArray;
    }
    public void setCourseName (String name)
    {
    	courseName =name;
    }
    public String getCourseName()
    {
    	return courseName;
    }
    public void displayMessage()
    {
    	System.out.printf("Total Sales Program\n%s!\n\n",
    	getCourseName() );
    }
     
    public void processSales ()
    {
     
    	outputSales();
     
    	System.out.printf("\n%s %d\n%s %d\n\n", "Highest Sales is", getMaximum(),
    	"Lowest Sales is", getMinimum() );
     
    	outputBarChart();
    }
     
    public int getMinimum()
    {
     
    int lowSales = sales[0][0];
     
    	for ( int totalSales[] : sale)
    	{
     
    		for (int sale :totalSales )
    		{
    			if ( sale < lowSales)
    				lowSales =sale;
    			}
    		}
    		 return lowSales;
    }
     
    public int getMaximum ()
    {
    	int highSale = sales[0][0];
     
    	for (int totalSales[] : sales)
    	{
    		for (int sale : totalSales)
    		{
    			if (sale > highSale)
    				highSale = sale;
    			}
    		}
    		return highSale;
    }
     
    public int getAvereage (int setofSales[])
    {
    	int total =0;
     
    	for (int sale : setofSales )
    		total +=sale;
     
    		return total / setofSales.length;
    }
     
    public void outputBarChart()
    {
    	System.out.println ("Overall sale distribution:" );
     
    	int frequency[] = new int[11];
     
    	for (int totalSales[] : sales)
    	{
    		for (int sale : totalSales )
    			++frequency [sale /10 ];
    		}
    	for (int count =0; count <frequency.length; count++)
    	{
    		if (count==10)
    			System.out.printf ( "%5d: ", 100);
    		else
    			System.out.printf ("%02d-%02d: ", count *10, count * 10 + 9);
     
    	for (int stars =0; stars <frequency [ count ]; stars++)
    		System.out.print ("*");
    		System.out.println();
    		}
    	}
    public void outputSales()
    {
    	System.out.println ("The sales are:\n");
    	System.out.print ( "            " );
     
    	for (int test=0; test <sales[0].length; test++)
    	System.out.printf ("Test %d ", test +1);
     
    	System.out.println ("Avereage");
     
    	for (int work =0; work <sales.length; work++)
    	{
    	System.out.printf ("Worker %2d", work +1);
     
    	for (int test : sales[ work] )
    		System.out.printf ("%8d", work);
     
    	int average = getAverage(sales[ work]);
    	System.out.printf ("9.2f\n", average);
    	}
    }
    }
    TotalSales.java:47: array required, but int found
    int lowSales = sales[0][0];
    ^
    TotalSales.java:49: cannot find symbol
    symbol : variable sale
    location: class TotalSales
    for ( int totalSales[] : sale)
    ^
    TotalSales.java:63: array required, but int found
    int highSale = sales[0][0];
    ^
    TotalSales.java:65: incompatible types
    found : int
    required: int[]
    for (int totalSales[] : sales)
    ^
    TotalSales.java:92: incompatible types
    found : int
    required: int[]
    for (int totalSales[] : sales)
    ^
    TotalSales.java:114: int cannot be dereferenced
    for (int test=0; test <sales[0].length; test++)
    ^
    TotalSales.java:123: foreach not applicable to expression type
    for (int test : sales[ work] )
    ^
    TotalSales.java:126: cannot find symbol
    symbol : method getAverage(int)
    location: class TotalSales
    int average = getAverage(sales[ work]);
    ^
    8 errors


    public class TotalSalesTest
    {
     
    	public static void main ( String args[])
    	{
     
    	int salesArray[][]= { {1, 1, 37},
    								{1, 2, 77},
    								{1, 3, 68},
    								{1, 4, 61} };
     
    	TotalSale myTotalSale = new TotalSale (
    	"Total Sales", salesArray);
    	myTotalSale.display();
    	myTotalSale.processSales();
    }
    }

    TotalSalesTest.java:12: cannot find symbol
    symbol : class TotalSale
    location: class TotalSalesTest
    TotalSale myTotalSale = new TotalSale (
    ^
    TotalSalesTest.java:12: cannot find symbol
    symbol : class TotalSale
    location: class TotalSalesTest
    TotalSale myTotalSale = new TotalSale (
    ^
    2 errors


    Please help me in advance.
    Last edited by KRUKUSA; March 18th, 2012 at 07:26 PM. Reason: please use [code] tags


  2. #2
    Junior Member
    Join Date
    Feb 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Total Sales Error

    bump? please helppppp meeeee

  3. #3
    Junior Member
    Join Date
    Feb 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Total Sales Error

    bump anyone?

  4. #4
    Member
    Join Date
    Jan 2012
    Location
    Hellas
    Posts
    284
    Thanks
    11
    Thanked 59 Times in 57 Posts

    Default Re: Total Sales Error

    Hello KRUKUSA!
    I think your compiler tells you exactly what are your errors. Remember that a 1d int array (sales[]) differs from a 2d int array(sales[][]). You should take a look at the Java API about Variables. And something else about your TotalSalesTest class, TotalSale is different from TotalSales.
    Hope it helps.

  5. #5
    Junior Member
    Join Date
    Feb 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Total Sales Error

    Quote Originally Posted by andreas90 View Post
    Hello KRUKUSA!
    I think your compiler tells you exactly what are your errors. Remember that a 1d int array (sales[]) differs from a 2d int array(sales[][]). You should take a look at the Java API about Variables. And something else about your TotalSalesTest class, TotalSale is different from TotalSales.
    Hope it helps.
    Thanks for the help i fixed the program and got it to display but it isn't working lik



    public

    class TotalSales
    {
    private String courseName;
    private int sales[][];

    public TotalSales (String name, int salesArray[][] )
    {

    courseName =name;
    sales = salesArray;
    }
    public void setCourseName (String name)
    {
    courseName =name;
    }
    public String getCourseName()
    {
    return courseName;
    }
    public void display()
    {
    System.out.printf("Total Sales Program\n%s!\n\n",
    getCourseName() );
    }

    public void processSales ()
    {

    outputSales();

    System.out.printf("\n%s %d\n%s %d\n\n", "Highest Sales is", getMaximum(),
    "Lowest Sales is", getMinimum() );

    outputBarChart();
    }

    public int getMinimum()
    {

    int lowSales = sales[0][0];

    for ( int totalSales[] : sales)
    {

    for (int sale :totalSales )
    {
    if ( sale < lowSales)
    lowSales =sale;
    }
    }
    return lowSales;
    }

    public int getMaximum ()
    {
    int highSale = sales[0][0];

    for (int totalSales[] : sales)
    {
    for (int sale : totalSales)
    {
    if (sale > highSale)
    highSale = sale;
    }
    }
    return highSale;
    }

    public int getAverage (int setofSales[])
    {
    int total =0;

    for (int sale : setofSales )
    total +=sale;

    return total / setofSales.length;
    }

    public void outputBarChart()
    {
    System.out.println ("Overall sale distribution:" );

    int frequency[] = new int[11];

    for (int totalSales[] : sales)
    {
    for (int sale : totalSales )
    ++frequency [sale /10 ];
    }
    for (int count =0; count <frequency.length; count++)
    {
    if (count==10)
    System.out.printf ( "%5d: ", 100);
    else
    System.out.printf ("%02d-%02d: ", count *10, count * 10 + 9);

    for (int stars =0; stars <frequency [ count ]; stars++)
    System.out.print ("*");
    System.out.println();
    }
    }
    public void outputSales()
    {
    System.out.println ("The sales are:\n");
    System.out.print ( " " );

    for (int test=0; test <sales[0].length; test++)
    System.out.printf ("Test %d ", test +1);

    System.out.println ("Average");

    for (int work =0; work <sales.length; work++)
    {
    System.out.printf ("Worker %2d", work +1);

    for (int test : sales[ work] )
    System.out.printf ("%8d", work);

    double average = getAverage(sales[work]);
    System.out.printf ("%9.2f\n", average);
    }
    }
    }




    public

    class TotalSalesTest
    {

    public static void main ( String args[])
    {

    int salesArray[][]= { {1, 1, 37},
    {1, 2, 77},
    {1, 3, 68},
    {1, 4, 61} };

    TotalSales myTotalSales = new TotalSales (
    "Total Sales", salesArray);
    myTotalSales.display();
    myTotalSales.processSales();
    }
    }



    It displays something like this.
    how come all the values aren't going into the first worker?

    Test 1 Test 2 Test 3 Average
    Worker 1 0 0 0 13.00
    Worker 2 1 1 1 26.00
    Worker 3 2 2 2 24.00
    Worker 4 3 3 3 22.00

Similar Threads

  1. Why wont my program calculate sales tax?
    By scholaryoshi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 28th, 2012, 07:30 PM
  2. Sales not working
    By JeremiahWalker in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 9th, 2012, 09:07 AM
  3. Type Erasure -- Sales pitch?
    By 2by4 in forum Collections and Generics
    Replies: 0
    Last Post: December 10th, 2011, 05:59 AM
  4. Sales Analysis for various products
    By faridzul90 in forum Java Theory & Questions
    Replies: 3
    Last Post: September 22nd, 2011, 08:36 AM
  5. I trying to calculate total price.
    By Muhanguzi in forum JDBC & Databases
    Replies: 6
    Last Post: June 15th, 2011, 03:35 PM