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 9 of 9

Thread: I somehow can't find problems with a few lines

  1. #1
    Member
    Join Date
    Jul 2011
    Posts
    62
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default I somehow can't find problems with a few lines

    // The quarterStats-program should be able to let the user
    // enter four sales-figures for 6 divisions of a company.
    // (For 4 quarters in a stock-market year.)
    // FOR HELP NEEDED, I SELECTED THE LINES THAT HAVE
    // SHOWN UP ERRONEOUS ON THE COMPILER.

    // Use this Scanner-class import-statement for input and output.
    import java.util.Scanner;

    // Use this DecimalFormat-class import-statement for numerical-setups.
    import java.text.DecimalFormat;

    public class QuarterStats
    {
    // Use the following variable-setup
    // for these matched-up purposes:
    final int QUARTERS = 4; // the rows of each sales-quarter,
    final int DIVISIONS = 6; // the columns of all 6 divisions,

    // the sales-figure array that will hold all of the figures,
    double[][] salesFigures = new double[QUARTERS][DIVISIONS];

    // the general-figure variable for each entry,
    double figure,

    // the variable for the highest sales-division for each quarter,
    highestQuart = salesFigures[0][0],

    // the increase or decrease of sales statistics,
    divInOrDecrease,

    // an average-sales variable,
    avSales,

    // the accumulator for the average,
    total;

    // a Scanner-class object named keys,
    Scanner keys = new Scanner(System.in);

    // and a DecimalFormat-object named numSetup.
    DecimalFormat numSetup = new DecimalFormat("#,##0.00");

    // Now get all of the entries.
    for (int rows = 0; rows < QUARTERS; rows++)
    {
    for (int cols = 0; cols < DIVISIONS; cols++)
    {
    System.out.println("What is division-" + cols + 1 + "\'s quarter-" + rows + 1 + " sales-figure?");
    figure = keys.nextDouble();
    salesFigures[rows][cols] = figure;
    }
    }

    // Finally, display data for each matched-up purpose.
    for (int row = 0; row < QUARTERS; row++)
    {
    total = salesFigures[row][col] + lastQuarter; // Use the accumulator for an average.

    // Use decision-structure to show division's increase or decrease
    // from the previous quarter.
    if (lastQuarter > salesFigures[row][col + 1])
    {
    divInOrDecrease = lastQuarter + salesFigures[row][col + 1];
    }
    else if (lastQuarter < salesFigures[row][col + 1])
    {
    divInOrDecrease = lastQuarter + salesFigures[row][col + 1];
    }
    else if (lastQuarter == 0)
    {
    lastQuarter += salesFigures[row][col + 1];
    }

    // Display all of the quarter's sales-figures.
    System.out.println("Division-" + col + 1 + " sales-figures:");

    for (int col = 0; col < DIVSIONS; col++)
    {
    System.out.println("Q" + rows + 1 + ": " + salesFigures[row][col]);
    lastQuarter = salesFigures[row][col];
    }

    avSale = total / 6; // Get the average.

    System.out.println("Quarter-1\'s average sales: " + numSetup.format(avSale));
    }

    for (int ro = 0; ro < QUARTERS; ro++)
    {
    for (int clmn = 0; clmn < DIVSIONS; clmn++)
    {
    if (salesFigures[ro][clmn] > highestQuart)
    highestQuart = salesFigures[ro][clmn];
    }

    // Display the highest division's sales for a quarter.
    System.out.println("Highest division's sales for Quarter-" + ro + 1 + ": " + numSetup.format(highestQuart));
    }
    }
    Last edited by SOG; May 10th, 2012 at 03:04 PM. Reason: To highlight correctly


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,170
    My Mood
    Hungover
    Thanks
    141
    Thanked 599 Times in 514 Posts

    Default Re: I somehow can't find problems with a few lines

    Please use the highlight tags when posting code.

    Also, please ask a specific technical question. What is wrong with this code? What are the problems with it? Have you stepped through this with a debugger, or at least added some print statements, to figure out where the flow of the program differs from what you expect it to do?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Member
    Join Date
    Jul 2011
    Posts
    62
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: I somehow can't find problems with a few lines

    How do I solve errors that include illegal start of type, as well as expected characters and identifiers that I didn't type in, when I am trying to make the program follow this procedure:

    1. Get 4 quarterly sales figures for 6 divisions of a company in a 2D-array.
    2. Display all of the things that are said to be displayed represented by those comments for each quarter.


    To find more detail to skim over about what went wrong, the error list I copied is below:

    QuarterStats.java:43: error: illegal start of type
    for (int rows = 0; rows < QUARTERS; rows++)
    ^
    QuarterStats.java:43: error: ')' expected
    for (int rows = 0; rows < QUARTERS; rows++)
    ^
    QuarterStats.java:43: error: illegal start of type
    for (int rows = 0; rows < QUARTERS; rows++)
    ^
    QuarterStats.java:43: error: <identifier> expected
    for (int rows = 0; rows < QUARTERS; rows++)
    ^
    QuarterStats.java:43: error: ';' expected
    for (int rows = 0; rows < QUARTERS; rows++)
    ^
    QuarterStats.java:43: error: > expected
    for (int rows = 0; rows < QUARTERS; rows++)
    ^
    QuarterStats.java:43: error: '(' expected
    for (int rows = 0; rows < QUARTERS; rows++)
    ^
    QuarterStats.java:54: error: illegal start of type
    for (int row = 0; row < QUARTERS; row++)
    ^
    QuarterStats.java:54: error: ')' expected
    for (int row = 0; row < QUARTERS; row++)
    ^
    QuarterStats.java:54: error: illegal start of type
    for (int row = 0; row < QUARTERS; row++)
    ^
    QuarterStats.java:54: error: <identifier> expected
    for (int row = 0; row < QUARTERS; row++)
    ^
    QuarterStats.java:54: error: ';' expected
    for (int row = 0; row < QUARTERS; row++)
    ^
    QuarterStats.java:54: error: > expected
    for (int row = 0; row < QUARTERS; row++)
    ^
    QuarterStats.java:54: error: '(' expected
    for (int row = 0; row < QUARTERS; row++)
    ^
    QuarterStats.java:87: error: illegal start of type
    for (int ro = 0; ro < QUARTERS; ro++)
    ^
    QuarterStats.java:87: error: ')' expected
    for (int ro = 0; ro < QUARTERS; ro++)
    ^
    QuarterStats.java:87: error: illegal start of type
    for (int ro = 0; ro < QUARTERS; ro++)
    ^
    QuarterStats.java:87: error: <identifier> expected
    for (int ro = 0; ro < QUARTERS; ro++)
    ^
    QuarterStats.java:87: error: ';' expected
    for (int ro = 0; ro < QUARTERS; ro++)
    ^
    QuarterStats.java:87: error: > expected
    for (int ro = 0; ro < QUARTERS; ro++)
    ^
    QuarterStats.java:87: error: '(' expected
    for (int ro = 0; ro < QUARTERS; ro++)
    ^
    21 errors
    Last edited by SOG; May 10th, 2012 at 03:05 PM.

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

    Default Re: I somehow can't find problems with a few lines

    Hello SOG!
    You can't put loops outside of a method or a constructor. That's why the compiler complains. Try creating a method (or a constructor) and then put your code inside.

  5. #5
    Member
    Join Date
    Jul 2011
    Posts
    62
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: I somehow can't find problems with a few lines

    Now that I have a main-method that the code is inside now, I get one last error-message after adding a closing brace up above the last 2 (when you really think about it):

    QuarterStats.java:102: error: class, interface, or enum expected
    }
    ^
    1 error

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

    Default Re: I somehow can't find problems with a few lines

    Quote Originally Posted by SOG View Post
    Now that I have a main-method that the code is inside now, I get one last error-message after adding a closing brace up above the last 2 (when you really think about it):

    QuarterStats.java:102: error: class, interface, or enum expected
    }
    ^
    1 error
    This is means you left line 102 out of the class. Check again your {}.

  7. #7
    Member
    Join Date
    Jul 2011
    Posts
    62
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: I somehow can't find problems with a few lines

    What do I check this {} for and how do I fix it?

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

    Default Re: I somehow can't find problems with a few lines

    Quote Originally Posted by SOG View Post
    What do I check this {} for and how do I fix it?
    I meant check again your curly braces, { }. You have probably made a mistake when you added the closing brace as you said in post #5.

  9. #9
    Member
    Join Date
    Jul 2011
    Posts
    62
    Thanks
    12
    Thanked 4 Times in 4 Posts

    Default Re: I somehow can't find problems with a few lines

    I fixed the rest of the remaining errors in the program, including {}.

Similar Threads

  1. [SOLVED] 2 Lines Stuffs.
    By Saintroi in forum What's Wrong With My Code?
    Replies: 9
    Last Post: May 11th, 2012, 08:22 AM
  2. Perpendicular Lines
    By captain in forum Object Oriented Programming
    Replies: 1
    Last Post: March 5th, 2012, 07:46 PM
  3. How would you get a JTextArea to know how many lines it had?
    By javapenguin in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 20th, 2011, 06:58 PM
  4. cannot find symbol variable lines 24, 25, 44, 45, 63, 64? Help!
    By ironman_777 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 26th, 2010, 01:48 PM
  5. My lines won't work!!!
    By The Mewzytion in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 2nd, 2010, 10:24 AM