Loops 在另一个类中查找方法时找不到符号错误
我的代码有问题 我的任务是让我的代码滚动这两个骰子,我做了1000次,每次这两个骰子的总和是7,然后我计数到递增1。直到循环停止在1000。这是我的密码。我正在尝试从类PairOfDice访问getTotalFaceValue的方法Loops 在另一个类中查找方法时找不到符号错误,loops,Loops,我的代码有问题 我的任务是让我的代码滚动这两个骰子,我做了1000次,每次这两个骰子的总和是7,然后我计数到递增1。直到循环停止在1000。这是我的密码。我正在尝试从类PairOfDice访问getTotalFaceValue的方法 问题是什么,它与循环有什么关系?第一个问题是我试图访问PairOfDice.getTotalFaceValue;在主方法中,但由于某种原因,我一直得到一个错误。我试着做PairOfDice var=newpairofdice;但这不起作用,第二个问题是,在我访问ge
问题是什么,它与循环有什么关系?第一个问题是我试图访问PairOfDice.getTotalFaceValue;在主方法中,但由于某种原因,我一直得到一个错误。我试着做PairOfDice var=newpairofdice;但这不起作用,第二个问题是,在我访问getTotalFaceValue方法之后,我需要做一个循环,每个循环的和是7,我将使count var增加1。。顺便说一句,我所有的程序都在同一个文件中,用适当的编程语言标记它
//********************************************************************
// Die.java Author: Lewis/Loftus
//
// Solution to Programming Project 5.11
//
// Represents one die (singular of dice) with faces showing values
// between 1 and the number of faces on the die.
//********************************************************************
public class Die
{
private final int MAX = 6; // maximum face value
private int faceValue; // current value showing on the die
//-----------------------------------------------------------------
// Constructor: sets the initial face value.
//-----------------------------------------------------------------
public Die()
{
faceValue = 1;
}
//-----------------------------------------------------------------
// Rolls the die and returns the result.
//-----------------------------------------------------------------
public int roll()
{
faceValue = (int) (Math.random() * MAX) + 1;
return faceValue;
}
//-----------------------------------------------------------------
// Face value mutator.
//-----------------------------------------------------------------
public void setFaceValue(int value)
{
faceValue = value;
}
//-----------------------------------------------------------------
// Face value accessor.
//-----------------------------------------------------------------
public int getFaceValue()
{
return faceValue;
}
//-----------------------------------------------------------------
// Returns a string representation of this die.
//-----------------------------------------------------------------
public String toString()
{
String result = Integer.toString(faceValue);
return result;
}
}
//********************************************************************
// PairOfDice.java Author: Lewis/Loftus
//
// Solution to Programming Project 4.9 and 5.11
//********************************************************************
public class PairOfDice
{
public Die die1, die2;
//-----------------------------------------------------------------
// Creates two six-sided Die objects, both with an initial
// face value of one.
//-----------------------------------------------------------------
public PairOfDice()
{
die1 = new Die();
die2 = new Die();
}
//-----------------------------------------------------------------
// Rolls both dice and returns the combined result.
//-----------------------------------------------------------------
public int roll()
{
return die1.roll() + die2.roll();
}
//-----------------------------------------------------------------
// Returns the current combined dice total.
//-----------------------------------------------------------------
public int getTotalFaceValue()
{
return die1.getFaceValue() + die2.getFaceValue();
}
//-----------------------------------------------------------------
// Returns the current value of the first die.
//-----------------------------------------------------------------
public int getDie1FaceValue()
{
return die1.getFaceValue();
}
//-----------------------------------------------------------------
// Returns the current value of the second die.
//-----------------------------------------------------------------
public int getDie2FaceValue()
{
return die2.getFaceValue();
}
//-----------------------------------------------------------------
// Returns the string representation of this pair of dice.
//-----------------------------------------------------------------
public String toString()
{
return "Die 1: " + die1.getFaceValue() + " Die 2: " +
die2.getFaceValue();
}
}
//
//
//
//
//*******************************************
public class ChidoriDiceRoller
{
public static void main(String [] args)
{
PairOfDice.getTotalFaceValue();
for(int i = 1;i<=1000 ; i++)
{
PairOfDice.getTotalFaceValue();//System.out.print(i + " \n");
}
}
}