0

/* 这些是我的课程,我在编译我的课程时遇到问题?我不确定出了什么问题*/

这将是我的枚举类,我将在我的案例陈述中使用它

 public enum Quarter
{
   First,
   Second,
   Third,
   Forth
 }

这些是我的类字段。我不太确定我在网上看到的扫描仪字段,但它编译不正确。这是将扫描仪类型声明为字段的正确方法吗?

  public class Quarterly
  {
    private final const ROW = 6;
    private final const COL = 4;
    private Scanner _scanner;


  public Quarterly(Scanner scanner) // This Constructor does not compile either? What am I doing Wrong???
  {
      this._scanner = scanner;
  }

这将是一种只接收用户输入的方法。但是我在这个案例陈述中遇到了麻烦

  private string GetMessage(Quarter quarter, int departmentNumber)
  {
     switch(quarter)
     {
      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++)
        {
        // This for statement is taking one column from the array in order to fill with input
             for (int col = 0; col < COL; col++)
             {
                // This will receive sale numbers from the six departments
                System.out.print(message + "[" + num + " ]. . . . . $ ");
                sales[row][col] = _scanner.nextDouble();
                num++;
                // This for statement will sum each department's input
                for (int i = 0; i < sales.length; i++);
                {
                total += sales[row][col];
                }  
             }
        }

return total;
}





/ This will be my main program.

 {
 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 ");
 }
4

3 回答 3

1

Java 中没有任何东西叫做 const。你的变量是什么类型的

private final const ROW = 6;
private final const COL = 4;
于 2013-11-09T05:43:05.070 回答
0

很多关于概率的缺失细节。

但这是我注意到的事情。

  1. const - Java 中没有 const
  2. 它应该是

    switch(quarter){
        case First:
    
  3. 在您的第二个代码段中,您缺少“}”

  4. 缺少进口
于 2013-11-09T17:05:17.077 回答
0

我看到了几件事。

首先,正确大写。(仅供参考,作为风格提示:常量,例如枚举值,通常都是大写,例如FIRST。)

 switch(quarter)
 {
  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+" ]. . . . . $ ";

 }

其次,在您使用的任何地方Scanner,执行以下操作之一

  1. import java.util.Scanner;在文件顶部添加。

  2. 使用全名java.util.Scanner而不是Scanner.

于 2013-11-09T05:24:55.373 回答