Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2005

Tip: Looking for answers? Try searching our database.

Newbie Question

Thread view: 
wendileigh - 28 May 2005 17:44 GMT
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();
  }
}
Hal Rosser - 28 May 2005 20:26 GMT
Does it compile ?
Try removing the 'f' from printf

System.out.print("hello");


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.