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));
}
}
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?
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:
- Get 4 quarterly sales figures for 6 divisions of a company in a 2D-array.
- 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
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.
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
Re: I somehow can't find problems with a few lines
Quote:
Originally Posted by
SOG
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 {}.
Re: I somehow can't find problems with a few lines
What do I check this {} for and how do I fix it?
Re: I somehow can't find problems with a few lines
Quote:
Originally Posted by
SOG
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.
Re: I somehow can't find problems with a few lines
I fixed the rest of the remaining errors in the program, including {}.