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: The Drive-a-Toyota Act
    ... take into consideration the total cost of acquiring a vehicle, insuring, ... replacement cost for another new vehicle. ... Assume two buyers buy exactly the same $25,000 car. ... old Toyotas are worth about half their original purchase price). ...
    (alt.autos.toyota)
  • Re: Can a Limited Utopia Exist?
    ... was living on around $1,000/month and I was living pretty well. ... Cost of living varies by a lot from place to place. ... lady's budget can be keeping a crummy car up and running. ... independence at that point. ...
    (rec.arts.sf.science)
  • Re: "Its Greener by Car" - Times story
    ... The biggest obstacle to overcome is the additional cost per ... Standard Family Car: Vauxhall Zafira, ... Now look at the rail fares. ... Those who quote the lower stress level of rail journeys conveniently ...
    (uk.railway)
  • Re: murderous motorist
    ... And yet even with those taxes car use is hugely subsidised, ... a cost which itself makes a substantial ... dent in the £24 Billion or so raised in fuel duty), ... petrol was 100.95p, Finnish petrol 102p German petrol 93.8p Dutch ...
    (uk.rec.cycling)