c# - Additional Methods that do not work? -
i realize can put data in method constructor calling , work. messing code , trying have additional methods calculations. problem book, , since not have instructor bug few weeks figured ask here.
any input? please , thank you
using system; using system.collections.generic; using system.linq; using system.text; namespace consoleapplication305 { class program { static void main(string[] args) { trip = new trip(); console.writeline(a); } class trip { int distancetraveled; double costgas; int numbergallon; int mpg; double cpm; public int distancetraveled { { return distancetraveled; } } public double costgas { { return costgas; } } public int numbergallon { { return numbergallon; } } public trip() { distancetraveled = 312; costgas = 3.46; numbergallon = 10; } public void milespergal() { mpg = distancetraveled / numbergallon; } public void costpermile() { cpm = costgas * mpg; } public override string tostring() { return string.format("the distance traveled is...{0} \nthe cost per gallon of gasoline is... {1} \nthe amount of gallons were... {2} \nthe miles per gallon attained were... {3} \nthe cost per mpg were... {4}", distancetraveled, costgas, numbergallon, mpg, cpm); } } }
}
if understand question correctly, should work you:
class trip { int distancetraveled; double costgas; int numbergallon; int mpg; double cpm; public int distancetraveled { { return distancetraveled; } } public double costgas { { return costgas; } } public int numbergallon { { return numbergallon; } } public trip() { distancetraveled = 312; costgas = 3.46; numbergallon = 10; mpg = milespergal(); cpm = costpermile(); } public int milespergal() { return distancetraveled / numbergallon; } public double costpermile() { return costgas * mpg; } public override string tostring() { return string.format("the distance traveled is...{0} \nthe cost per gallon of gasoline is... {1} \nthe amount of gallons were... {2} \nthe miles per gallon attained were... {3} \nthe cost per mpg were... {4}", distancetraveled, costgas, numbergallon, mpg, cpm); } }
Comments
Post a Comment