public enum Quarter
{
FIRST,
SECOND,
THIRD,
FOURTH,
}
import java.util.*;
public class Quarterly
{
private final int ROW = 6;
private final int COL = 4;
private Scanner _scanner;
我想知道如果我在这里适当地声明了我的扫描仪类,我在教科书中看到了这一点,但我不确定它是否有效?还有另一种方法可以写这个吗?
public Quarterly(Scanner scanner)
{
this._scanner = scanner;
}
这个方法编译不正确有什么问题呢?它显示三个错误
该方法的标题显示编译错误“错误:找不到符号”
这两个错误都显示在我的所有四个案例陈述中
Error #1 : "an enum switch case label must be the unqualified name of the numeric constant.
Error #2: " Duplicate case label.
``
private string GetMessage(Quarter quarter, int departmentNumber)// This shows an error that says " Error: Cannot Find Symbol"
{
// This case Statement is showing Two compiling errors that in every case just cannot find a way to fix them.
switch(quarter)
{
// Both These Errors are showing in all of my four case statement
// Error #1 : "an enum switch case label must be the unqualified name of the numeric constant"
// Error #2: " Duplicate case label.
case Quarter.FIRST:
return "Enter The First Quarterly Sales For Department [ " + departmentNumber+" ]. . . . . $ ";
case Quarter.SECOND:
return "Enter a The Second Quarterly Sales For Department [ " + departmentNumber+" ]. . . . . $ ";
case Quarter.THIRD:
return "Enter a The Third Quarterly Sales For Department [ " + departmentNumber+" ]. . . . . $ ";
case Quarter.FORTH:
return "Enter a The Forth Quarterly Sales For Department [ " + departmentNumber+" ]. . . . . $ ";
}
}
这是一种方法,它将把输入分配给我的数组并进行总结,任何人都可以查看这个方法,看看他们是否看到我编译它时可能出现的任何错误。
public double GetTotalForDepartments(Quarter quarter)
{
double [][] sales = new double [ROW][COL];
int num = 1;
double total = 0;
for (int row = 0; row < ROW ; row++)
{
for (int col = 0; col < COL; col++)
{
// This will input value into my array
sales[row][col] = _scanner.nextDouble();
num++;
// This will Total my array
for (int i = 0; i < sales.length; i++);
{
total += sales[row][col];
}
}
return total;
}
}
}
这将是我的主要内容。这是我从我的班级中调用我所有的方法。
public static void main(String[] args)
{
double test1;
double test2;
double test3;
double test4;
Scanner keyboard = new Scanner(System.in);
Quarterly helper = new Quarterly(keyboard);
test1 = helper.GetTotalForDepartments(Quarter.FIRST);
System.out.println(" Test 1 = " + test1);
test2 = helper.GetTotalForDepartments(Quarter.SECOND);
System.out.println(" Test 2 = " + test2);
test3 = helper.GetTotalForDepartments(Quarter.THIRD);
System.out.println(" Test 3 = " + test3);
test4 = helper.GetTotalForDepartments(Quarter.FOURTH);
System.out.println(" Test 4 = " + test4 " /n ");
}