请原谅它的长度,但是这里有两个程序,两者完全相同,但是一个有一个没有setter,getter和构造函数的程序。
我之前已经学过一个基本的C ++类,并且不记得其中的任何一个,而现在我没有看到它们的意义,如果有人可以用拉面的术语来解释它们,我将非常感激。目前,它们似乎不过是浪费空间,以使我的代码看起来更长,但老师说它们很重要(到目前为止,就是这样)。
提前致谢!现在是代码:Mileage.java:
package gasMileage;
import java.util.Scanner; //program uses class Scanner
public class Mileage
{
public int restart;
public double miles, gallons, totalMiles, totalGallons, milesPerGallon;
public Mileage(int newRestart, double newMiles, double newGallons,
double newTotalMiles, double newTotalGallons, double newMilesPerGallon)
{
setRestart(newRestart);
setMiles(newMiles);
setGallons(newGallons);
setTotalMiles(newTotalMiles);
setTotalGallons(newTotalGallons);
setMilesPerGallon(newMilesPerGallon);
}
public void setRestart(int newRestart)
{
restart = newRestart;
}
public int getRestart()
{
return restart;
}
public void setMiles(double newMiles)
{
miles = newMiles;
}
public double getMiles()
{
return miles;
}
public void setGallons(double newGallons)
{
gallons = newGallons;
}
public double getGallons()
{
return gallons;
}
public void setTotalMiles(double newTotalMiles)
{
totalMiles = newTotalMiles;
}
public double getTotalMiles()
{
return totalMiles;
}
public void setTotalGallons(double newTotalGallons)
{
totalGallons = newTotalGallons;
}
public double getTotalGallons()
{
return totalGallons;
}
public void setMilesPerGallon(double newMilesPerGallon)
{
milesPerGallon = newMilesPerGallon;
}
public double getMilesPerGallon()
{
return milesPerGallon;
}
繁星淼淼
神不在的星期二
相关分类