Java:计算存储在类中的数据

时间:2014-10-22 10:22:56

标签: java

重要说明:这是我上一个问题的重新发布,但是有一些具体的信息使得它的答案无法在我的程序中使用。谢谢你的回答,我很抱歉,我很蠢。

从项目说明:"不使用任何动态数据结构,如arraylists。" 我也无法以任何方式更改类中的变量。

我有以下课程:

public class Job_16997761 {

  private int jobID;             // unique job identification number
  private int customerID;        // unique customer identification number
  private String registration;   // registration number for vehicle for this job
  private String date;           // when the job is carried out by mechanic
  private String day;            // day of the week that job is booked for
  private double totalFee;       // total price for the Job
  private int[] serviceCode;     // the service codes to be carried out on the vehicle for the job

  //Constructor
  public Job_16997761(int jobID, int customerID, String registration, 
          String date, String day, double totalFee, int[] serviceCode) {
      this.jobID = jobID;
      this.customerID = customerID;
      this.registration = registration;
      this.date = date;
      this.day = day;
      this.totalFee = totalFee;
      this.serviceCode = serviceCode;
  }

  //Get and set methods removed because irrelevant

}

最后的数字只是我的学生证,它必须在那里,所以不要介意。程序从文本文件中读取一堆数据,并使用主解决方案中的以下代码将其存储为类(不是类代码的一部分):

public static void getJobFile() throws FileNotFoundException {
        Job_16997761[] job = new Job_16997761[0];
        System.out.print("Please enter the name of the Job text file: ");
        jobFile = kb.next();
        Scanner jobScan = new Scanner(new File(jobFile));
        while (jobScan.hasNext()) {
            countC ++;
            jobScan.nextLine();
        }
        job = new Job_16997761[countC];
        countC = 0;
        while (jobScan.hasNext()) {
            String[] line = jobScan.nextLine().split(",");
            int[] tempArray = new int[line.length - 6];
            for (int i = 0; i < tempArray.length; i++) {
                tempArray[i] = Integer.parseInt(line[i + 6]);
            }
            job[countC] = new Job_16997761(Integer.parseInt(line[0]), Integer.parseInt(line[1]), 
                    line[2], line[3], line[4], Double.parseDouble(line[5]), tempArray);
            countC ++;
        }
    }

项目的一部分是根据用户输入的数据创建新作业。然而每个&#34;天&#34;最多只能分配12个作业。我不确定如何找到x天的工作数量。如果我不需要,我不想使用文件,但我不确定这是否可能。

0 个答案:

没有答案