Java:计算存储在类中的数据
重要提示:这是我最后一个问题的复述,但是有一些特定信息使得我的程序无法使用它的答案。谢谢你的回答,很抱歉我搞错了 根据项目说明:“不要使用任何动态数据结构,如ArrayList。”我也不能以任何方式更改类中的变量 我有以下课程:Java:计算存储在类中的数据,java,Java,重要提示:这是我最后一个问题的复述,但是有一些特定信息使得我的程序无法使用它的答案。谢谢你的回答,很抱歉我搞错了 根据项目说明:“不要使用任何动态数据结构,如ArrayList。”我也不能以任何方式更改类中的变量 我有以下课程: public class Job_16997761 { private int jobID; // unique job identification number private int customerID; // u
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()引发FileNotFoundException{
Job_16997761[]Job=新Job_16997761[0];
System.out.print(“请输入作业文本文件的名称:”);
jobFile=kb.next();
扫描仪作业扫描=新扫描仪(新文件(作业文件));
while(jobScan.hasNext()){
c++;
jobScan.nextLine();
}
job=新job_16997761[countC];
countC=0;
while(jobScan.hasNext()){
String[]line=jobScan.nextLine().split(“,”);
int[]tempArray=newint[line.length-6];
for(int i=0;i
项目的一部分是根据用户输入的数据创建一个新作业。但是,每个“天”最多只能分配12个工作。我不确定如何着手寻找x日的工作数量。如果不需要,我不想使用该文件,但我不确定这是否可行。创建变量(每天一个)并增加它们。但是如何?我不知道如何从整个Job类中获取数据。也许我对这个问题的理解是完全错误的,但是你不能在while循环中创建int-monday这样的变量,并且总是在[3]行中创建。等于(“星期一”)增加该计数器,并且只有在星期一<12创建一个新的Job对象时?…嗯。事实上,这是可行的。我想我能做到,谢谢!
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 ++;
}
}