Newbie Question



I am working on a homework assignment. The assignment is to calculate the
cost of a car based on options. I can get the cost to work, but I also
need to print out the price of the options - this I can't get to work.

I am working with two files
Car
and CarPurchase - code is pasted below from both. I have been working on
this for hours. I have tried putting it in my if statement
System.out.printf("The style price is 1000");
(this # will change for each option). I have tried also putting at
different places in each file. Nothing works. Please anyone help me!!!
Code is Car:
public class Car
{
public String style;
public float basePrice = 20000; // base price of carfloat basePrice =
20000; //
public float totalCost = basePrice;

public void setstyle(String styleprice)
{
style = styleprice;
}

public String getstyle()
{
if ( style == "1" )

{
totalCost = totalCost + 0;
}
if ( style == "2" )
{
totalCost = (totalCost + 800);
}

if (style == "3")
{
totalCost = (totalCost + 2000);

}

return style;

}

public void displayMessage()
{


System.out.printf("The style type is \n%s!\n", getstyle() );
if (getstyle() == "1" )
{
System.out.printf("The style price is 1000");
}

System.out.println("Total cost is: $" + totalCost );

}
}

Code in Car Purchase
import java.util.Scanner;
import java.io.*;
//import java.io.*;

public class CarPurchase
{
public static void main(String args[])throws IOException

{
Scanner input = new Scanner (System.in);

Car myCar = new Car();

System.out.printf("Initial style is: %s\n\n", myCar.getstyle() );

System.out.println("What style would you like (1=Hatchback, 2=Sedan,
3=Wagon )?");





BufferedReader stdin = new BufferedReader ( new InputStreamReader(
System.in ) );
String inData = stdin.readLine();

myCar.setstyle ( inData);

System.out.println();

myCar.displayMessage();
}
}

.



Relevant Pages

  • Re: von Mises Institute on Henry George
    ... >>The cost per car for the CEO is much less than transport costs. ... But add in all the other overpaid execs, the stock options, ... > It was real estate lending that sank the Japanese financial system, ...
    (sci.econ)
  • Re: Camera Card Reader
    ... the OEM will install XP at extra cost. ... I would say two things: 1) there ARE cases where Windows gets so tangled up that a reboot is the only reasonable cure and 2) you don't need to do that on a weekly or monthly basis with a car. ... I also know that the people doing this sort of thing actually view electronics not as a cost, but as a cost SAVINGS because it is FAR cheaper to tweak a computer chip to, say, provide emissions support for a different state or country, than it is to completely redo the entire fuel-air system. ... If our SKIM or those of other makers could be easily and routinely overcome by beaming EMF energy at either the key fob itself or the engine compartment where the hidden receiver and computer are, doncha think the car companies would find out and fix it? ...
    (rec.photo.digital)
  • Re: Almost like a slow motion civil war
    ... The squared off Town Car, the rounded off Continental, and one specialty type car would do the trick. ... For the cost of making the original membrane and then replacing it repeatedly you can buy a barge full of diesel fuel which is getting 65 MPG in the Escort in Europe. ... The problem with battery powered cars is that batteries will never be good enough to make a usable car. ... The energy cost and environmental cost of packing a huge amount of lithium ion batteries into a car is a much worse solution that a clean diesel such as VW and Mercedes already have at a reasonable cost. ...
    (rec.autos.sport.nascar)
  • Re: Camera Card Reader
    ... the OEM will install XP at extra cost. ... do that on a weekly or monthly basis with a car. ... Key Immobilizer Module) in each key fob, ...
    (rec.photo.digital)
  • Re: VIC, repair on not?
    ... If a similar replacement will cost you a tenner, ... If I was spending 'good money' on a car, ... That's what it's WORTH. ... cheap repair of some good functional transport. ...
    (uk.rec.cars.maintenance)