我使用多维数组来存储特定销售人员(1到4个销售人员)销售的产品总量(产品范围1到5).
T在第1行到第4行中安排了salesPersons,在第1列到第5列中安排了产品ID.
我唯一不能做的就是遍历各行以获得每个产品的总数,即第1列:第1行到第4行的总和=总产品1,第2列:第1行到第4行的总和=产品2总数等.
请参阅测试salesTest应用程序代码,然后是Sales类:
/*
test application for sales class
*/
package salestest;
import SalesLibary.Sales;
public class SalesTest {
public static void main(String[] args) {
// pass monthly stats to 4r(salespesons) * c5(products 1 to 5) using initialization method
int monthlySales [][]= {{13, 23, 45, 67, 56},
{43, 65, 76, 89, 90},
{43, 45, 76, 98, 90},
{34, 56, 76, 43, 87}};
//pass default values to constructor when creating object of class
Sales companySales = new Sales("Monneys Inc.", monthlySales);
companySales.displayMessage(); …Run Code Online (Sandbox Code Playgroud) 我的目标是在IntelliJ上读取文本文件。但是,当我运行代码时,收到“ FileNotFoundException”消息。我的文件存在。我仔细检查了一下,以确保路径正确。我一直在寻找Stack Overflow的答案,阅读我遇到的每个问题,但是没有人提供具体的解决方案。
这是我的代码:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
public class LetterGrader {
public static void main(String[] args) {
String curDir = new File(".").getAbsolutePath();
System.out.println("Current sys dir: " + curDir);
try {
File inputData = new File("input.txt");
BufferedReader br = new BufferedReader(new FileReader(inputData));
} catch (IOException e) {
System.out.println("File not found");
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是显示的错误消息。
File not found
java.io.FileNotFoundException: input.txt (The system cannot find the file specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileReader.<init>(FileReader.java:72) …Run Code Online (Sandbox Code Playgroud)