我无法弄清楚我在这里做错了什么;您可以通过“//”部分看到,我尝试了不同的方法:
public class survey {
// instance variables - replace the example below with your own
private double total = 12467;
// private double percentage = 100;
private double one = total * .14; // percentage;
private double citrus = total * .64; // percentage;
public void results(int total) {
System.out.println("Number of people surveyed:" + total);
System.out.println("Number who purchase one or more energy drinks:"
+ one);
System.out.println("Number who prefer citrus flavored energy drinks:"
+ citrus);
}
}
这就是我最终做的,解决了错误。感谢大家的及时回复!
/**
* Write a description of class survey here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class survey
{
// instance variables - replace the example below with your own
private double total = 12467;
private double one = 14 ;
private double citrus = 64 ;
private int oneperc;
private int citrusperc;
{
oneperc = (int) ((total*one/100));
}
{
citrusperc = (int) ((total*citrus/100));
}
public void results(int total)
{
System.out.println("Number of people surveyed:" + total);
System.out.println("Number who purchase one or more energy drinks:" + oneperc);
System.out.println("Number who prefer citrus flavored energy drinks:" + citrusperc);
}
}