Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Another Car Class problem
New Posts  All Forums:Forum Nav:

Another Car Class problem

post #1 of 5
Thread Starter 
I have been working on this project trying to figure out as much as I can before asking here and now I am kind of stuck. I can't really figure out how to do the changeOil reminder method, so that it resets once I have changed the oil as well as a little trouble for the checkOil method (cant get it to compile.) I am a Java n00b, so please keep this in mind. All input is appreciated immensely!

This is just the car class, I still have to write a test class.

There are also some challenge requirements

-adding an on/off to the car that determines what functions you can use (e.g. the car must be turned off to change and check oil)

-modifying the void addGas (double gas) method to check for three possibilities, 1) provide a warning message if the number of gallons results in the tank overflowing but still fill the tank; 2) provide a warning message if the value is negative and do not modify the gas tank; or 3) add the provided amount of gallons to the tank. For all conditions,print a message showing the amount of gas in the tank after the fill up. See sample output
below.

-modifying int drive to check for three possibilities: 1) print a warning message if the parameter is negative and do not update an instance members; 2) print a warning message if the car runs out of gas during the trip and the miles driven. Only add the actual miles driven before running out of gas and update the gas tank. Or 3) modify the odometer and amount of gas to reflect the miles driven and print an appropriate message.

I am not to concerned with the challenges right now as I have yet to setup a successful simple version of the program

Again any help is appreciated.


Some sample outputs are:

The Generic Car engine must be on to drive
The Generic Car engine started
The Generic Car drove 100 miles
65 Mustang says honk! honk!
The 65 Mustang engine must be off to change the oil
The 65 Mustang engine was turned off
The Honda Civic now has 10.594713656387665 gallons of gas
The Honda Civic oil is OK
The Honda Civic engine started
The Honda Civic ran out of gas after 240 miles

Quote:
public class Car
{
private String makeModel;
private int odometer, changeOil;
private double gasGuage, milesPerGallon;
private final double gasCapacity = 12.5;

public Car()
{
makeModel = "Generic Car";
odometer = 0;
changeOil = odometer + 500;
gasGuage = 12.5;
milesPerGallon = 22.7;
}

public Car(String model, double mpg)
{
makeModel = model;
milesPerGallon = mpg;
}

public int checkOdometer()
{
return odometer;
}

public double checkGasGuage()
{
return gasGuage;
}


public void honkHorn()
{
system.out.println("The " + model + "says Beep Boop Bop Boop!");
}
public void addGas(double gas)
{
gasGuage += gas;
}
public void drive(int miles)
{
odometer += miles;
gasGuage -= (miles*mpg);
}
public void changeOil()
{

}
public void checkOil()

if (changeOil < odometer + 500)
system.out.println("The " + model +"'s Oil is OK, no need to change!");
else
{
system.out.println("Time to change the " + model +"'s oil!");
}
}
One-Two Punch
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.6gHz ASrock Extrem3 Gen3 GIGABYTE GV-N570OC-13I GeForce GTX 570 8GB G.SKILL Ripjaws X CL8 1600mhz 
Hard DriveOptical DriveOSMonitor
500 GB Seagate Samsung Combo Windows 7 Ultimate 22inch samsung 2ms 
KeyboardPowerCaseMouse
Saitek Eclipse Xclio Greatpower 650w Antec 300 Illusion Logitech G9 
  hide details  
Reply
One-Two Punch
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.6gHz ASrock Extrem3 Gen3 GIGABYTE GV-N570OC-13I GeForce GTX 570 8GB G.SKILL Ripjaws X CL8 1600mhz 
Hard DriveOptical DriveOSMonitor
500 GB Seagate Samsung Combo Windows 7 Ultimate 22inch samsung 2ms 
KeyboardPowerCaseMouse
Saitek Eclipse Xclio Greatpower 650w Antec 300 Illusion Logitech G9 
  hide details  
Reply
post #2 of 5
My advice is to quit being a code monkey and figure out the pseudo-code for those methods before writing down ANY code.
Primary PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II 720 (2.8 ghz) BIOSTAR A780L3L (AM3) MSI GeForce 9800GT G.Skill Ripjaws Series DDR3 1600 (8GB) 
Hard DriveOSMonitorPower
Crucial M4 64GB / Samsung F3 1TB Windows 7 Pro (64-bit) Dell SP2309W (2048x1152) PC Power & Cooling 610W 
CaseMouse
Cooler Master Elite 430 RC Logitech MX518 
  hide details  
Reply
Primary PC
(13 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II 720 (2.8 ghz) BIOSTAR A780L3L (AM3) MSI GeForce 9800GT G.Skill Ripjaws Series DDR3 1600 (8GB) 
Hard DriveOSMonitorPower
Crucial M4 64GB / Samsung F3 1TB Windows 7 Pro (64-bit) Dell SP2309W (2048x1152) PC Power & Cooling 610W 
CaseMouse
Cooler Master Elite 430 RC Logitech MX518 
  hide details  
Reply
post #3 of 5
Thread Starter 
This is the first I have attempted a program by myself. I know its not that complicated, but I have been rereading chapters of my book and searching all over to make sense of it. I'm not just asking for answers, posting here was my last choice to try to get some help.

Anyway I got down the basic car class and test class. It compiles and runs fine with the proper outputs. Now I am attempting the challenge part which should be fun.

Thanks for your generalized advice
One-Two Punch
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.6gHz ASrock Extrem3 Gen3 GIGABYTE GV-N570OC-13I GeForce GTX 570 8GB G.SKILL Ripjaws X CL8 1600mhz 
Hard DriveOptical DriveOSMonitor
500 GB Seagate Samsung Combo Windows 7 Ultimate 22inch samsung 2ms 
KeyboardPowerCaseMouse
Saitek Eclipse Xclio Greatpower 650w Antec 300 Illusion Logitech G9 
  hide details  
Reply
One-Two Punch
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.6gHz ASrock Extrem3 Gen3 GIGABYTE GV-N570OC-13I GeForce GTX 570 8GB G.SKILL Ripjaws X CL8 1600mhz 
Hard DriveOptical DriveOSMonitor
500 GB Seagate Samsung Combo Windows 7 Ultimate 22inch samsung 2ms 
KeyboardPowerCaseMouse
Saitek Eclipse Xclio Greatpower 650w Antec 300 Illusion Logitech G9 
  hide details  
Reply
post #4 of 5
Quote:
Originally Posted by heyladies View Post
This is the first I have attempted a program by myself. I know its not that complicated, but I have been rereading chapters of my book and searching all over to make sense of it. I'm not just asking for answers, posting here was my last choice to try to get some help.

Anyway I got down the basic car class and test class. It compiles and runs fine with the proper outputs. Now I am attempting the challenge part which should be fun.

Thanks for your generalized advice
Please feel free to continue to come here when you need some help. We know you aren't just looking for the answer, but this forum was made so that you could come here and talk it out. One of the best ways to learn in the real world is by doing everything you can on your own, and then when you get stuck (everyone gets stuck eventually), you talk it out with another developer and at that point you're just a huge sponge absorbing every morsel of knowledge.

Glad you worked it out. Next time let us know the compile error if you're having issues compiling, too!
Edited by Plex - 10/11/11 at 5:53pm
Intellect v2
(9 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7-6700K Processor ASUS ROG MAXIMUS VIII HERO LGA1151 DDR4 M.2 SAT... EVGA GTX 1080 SC ACX 3.0 Crucial Ballistix Sport 32GB DDR4 2400 MT/s (PC... 
CoolingKeyboardPowerCase
Noctua NH-D15 Das Keyboard 4 Professional (Brown) Corsair AX860 Fractal Design Define R5 
Mouse
MIONIX NAOS 7000 
  hide details  
Reply
Intellect v2
(9 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i7-6700K Processor ASUS ROG MAXIMUS VIII HERO LGA1151 DDR4 M.2 SAT... EVGA GTX 1080 SC ACX 3.0 Crucial Ballistix Sport 32GB DDR4 2400 MT/s (PC... 
CoolingKeyboardPowerCase
Noctua NH-D15 Das Keyboard 4 Professional (Brown) Corsair AX860 Fractal Design Define R5 
Mouse
MIONIX NAOS 7000 
  hide details  
Reply
post #5 of 5
Thread Starter 
EDIT: derp forgot my ()
Edited by heyladies - 10/11/11 at 9:54pm
One-Two Punch
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.6gHz ASrock Extrem3 Gen3 GIGABYTE GV-N570OC-13I GeForce GTX 570 8GB G.SKILL Ripjaws X CL8 1600mhz 
Hard DriveOptical DriveOSMonitor
500 GB Seagate Samsung Combo Windows 7 Ultimate 22inch samsung 2ms 
KeyboardPowerCaseMouse
Saitek Eclipse Xclio Greatpower 650w Antec 300 Illusion Logitech G9 
  hide details  
Reply
One-Two Punch
(13 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500k 4.6gHz ASrock Extrem3 Gen3 GIGABYTE GV-N570OC-13I GeForce GTX 570 8GB G.SKILL Ripjaws X CL8 1600mhz 
Hard DriveOptical DriveOSMonitor
500 GB Seagate Samsung Combo Windows 7 Ultimate 22inch samsung 2ms 
KeyboardPowerCaseMouse
Saitek Eclipse Xclio Greatpower 650w Antec 300 Illusion Logitech G9 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Another Car Class problem