java - 如何正确同步类之间的向量以避免使用静态?
问题描述
我有一个读取向量向量的类,它甚至包含一个字符串名称和包含玩家“投注”的内部向量。
但是,我在阅读向量中使用静态,如果我删除静态这个词,当在比较类中向量始终为零时。(我知道我在比较类中给出了一个新对象,它与之前填充的向量无关)
我想更改代码以同步 3 个类之间的向量,以便我可以进行正确的参数传递,但我不知道该怎么做。
您能否向我解释一下如何正确同步类之间的向量?
请记住,它不仅仅是向量,它们是由字符串名称 + 下注向量组成的下注类型对象。
此类 readTemplate 有一个静态声明: public static int[] templateVector= new int [13];
CLASS readTemplate - 部分代码:
public void readTemplate() throws NumberFormatException, IOException {
File templatesFile= new File ("C:\\Temp\\templatesFile.txt");
FileReader fr = new FileReader(templatesFile);
BufferedReader br = new BufferedReader(fr);
String row;
int j = 0;
while((row= br.readLine()) != null) {
String[] strings = row.split(" ");
for (String str : strings) {
Integer foo = Integer.parseInt(str);
templatevector[j] = foo;
j++;
}
}
br.close();
fr.close();
}
部分代码,仅用于理解目的:
类 generateResults(将此模板文件与投注进行比较以找到获胜者)
public void generateResult() throws IOException {
ReadTemplate Template = new ReadTemplate();
ReadBets a = new ReadBets();
File output = new File ("C:\\Temp\\output.txt");
FileWriter fw = new FileWriter("c:\\Temp\\output.txt");
BufferedWriter bw = new BufferedWriter(fw);
bw.write("TEMPLATE READ:");
for (int j = 0; j < template.vectorTemplate.length; j++) {
bw.write(template.vectorTemplate[j] + " ");
}
bw.newLine();
bw.write("+--Result Bets:--+");
bw.newLine();
try {
if (!output.exists()) {
output.createNewFile();
}
for(int j = 0; j < size; j++) {
int i = 0;
int counter = 0;
for(int x = 0; x < template.vectorTemplate.length; x++) {
if (a.totalStakes[j].vectorStakes[i] == template.vectorTemplate[x]) {
counter++;
}
i++;
}
}
非常感谢任何花时间向我解释的人。
解决方案
推荐阅读
- dictionary - 从 xml 转储模板中提取德语动词变位
- windows - 批处理 - 循环遍历文本文件
- libvlcsharp - 使用 libvlcsharp 镶嵌 UDP 流的正确方法
- sql - 涉及来自不同表的数据的 SQL 查询
- java - 为什么显示图像的这段代码在构建到 jar 时会给出“错误”?
- python - 我正在尝试使用烧瓶构建 Web 应用程序,但我对 CSS 所做的更改不再反映在它上面。有谁知道如何解决这一问题?
- asp.net-core-mvc - 页面验证失败时在 PartialView 中重新填充文本框
- php - 为什么 in_array 对此搜索返回 false?
- neural-network - 优化器步骤后网络的权重保持不变
- java - 你如何显示用户在移动数独游戏中按下的位置?