Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Pretty basic java program..need some help!

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Pretty basic java program..need some help!

    Hey guys need some help on this program. I am simply trying to write a program that does the following....

    There is an appliance store that is offering 1% (0.01) financing for 12 months on any purchase.
    I need to use constants for the finance rate and number of months (which i think i got)
    Have the user enter their purchase price
    Formatting ALL numeric output with two decimals, tell the user how much their monthly payment
    will be (using the formula below) and the total amount to be paid.
    monthly payment = ( (purchase price* financing rate) + purchase price) / months

    here is my code so far....
    import java.util.Scanner;


    public class rate
    {
    public static final int RATE = 0.01;
    public static final int MONTH = 12;
    public static void main(String[] args)
    {

    System.out.println(RATE);
    System.out.println(MONTH);
    Scanner s = new Scanner(System.in); // create a Scanner object
    String input; // read in user input as a string
    int qty; // number of items purchased

    System.out.print("Price of purchased item: "); // user prompt
    input = s.nextLine(); // read input as a string
    purchase price = Integer.parseInt(input);

    System.out.print("Your monthly payment: "); // user prompt
    input = s.nextLine(); // read input as a string
    financing rate = Integer.parseInt(input); // convert to int

    System.out.println("Total purchase order = $" ( (purchase price* financing rate) + purchase price) / months);

    } // end main

    } // end class Lab1

    It doesn't want to compile I get errors for having 0.01 and also i recieve numerous errors with

    System.out.println("Total purchase order = $" ( (purchase price* financing rate) + purchase price) / months);

    Any help is appreciated!
    Have a nice day


  2. #2
    Forum VIP
    Join Date
    Oct 2010
    Posts
    275
    My Mood
    Cool
    Thanks
    32
    Thanked 54 Times in 47 Posts
    Blog Entries
    2

    Default Re: Pretty basic java program..need some help!

    What exactly are your compile time errors? It is quite difficult to assist unless you provide exactly what errors you get a compile time, however I would check all your
    parantheses on the println, remember you have to use the '+' in order to conc strings like that. (You can use StringBuilder.. however I don't feel like going to that)

    Example of printing something to System.out
    int i = 0;
    String str = "Some String";
    System.out.println("i = "+i+"str = "+str+" i+1 = "+(i+1));
    Last edited by Tjstretch; January 24th, 2012 at 11:51 PM.

  3. #3
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Pretty basic java program..need some help!

    Paste the errors messages here so that we could have a look over them.
    purchase price = Integer.parseInt(input);
    Where is purchase price declared/initialized? And variables can't have whitespace in their names.
    financing rate = Integer.parseInt(input); // convert to int
    Where is financing rate declared/initialized? And variables can't have whitespace in their names.
    System.out.println("Total purchase order = $" ( (purchase price* financing rate) + purchase price) / months);
    Concatenate your variables values with the String ones by using concatenation operator.

  4. #4
    Junior Member
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Pretty basic java program..need some help!

    code-import java.util.Scanner;


    public class rate
    {
    public static final int RATE = 1;
    public static final int MONTH = 12;
    public static void main(String[] args)
    {

    System.out.println(RATE);
    System.out.println(MONTH);
    Scanner s = new Scanner(System.in); // create a Scanner object
    String input; // read in user input as a string

    int purchaseprice; // number of items purchased
    int financingrate; // number of items purchased


    System.out.print("Price of purchased item: "); // user prompt
    input = s.nextLine(); // read input as a string
    purchaseprice = Integer.parseInt(input); //

    System.out.print("Quantity: "); // user prompt
    input = s.nextLine(); // read input as a string
    financingrate = Integer.parseInt(input); // convert to int

    System.out.println("Total purchase order = $" ( (purchaseprice* financingrate) + purchaseprice) / MONTH);

    } // end main

    } // end class

    errors
    rate.java:37: ')' expected
    System.out.println("Total purchase order = $" ( (purchaseprice* financingrate) + purchaseprice) / MONTH);
    ^
    rate.java:37: not a statement
    System.out.println("Total purchase order = $" ( (purchaseprice* financingrate) + purchaseprice) / MONTH);
    ^
    rate.java:37: ';' expected
    System.out.println("Total purchase order = $" ( (purchaseprice* financingrate) + purchaseprice) / MONTH);
    ^
    rate.java:37: not a statement
    System.out.println("Total purchase order = $" ( (purchaseprice* financingrate) + purchaseprice) / MONTH);
    ^
    rate.java:37: ';' expected
    System.out.println("Total purchase order = $" ( (purchaseprice* financingrate) + purchaseprice) / MONTH);
    thanks alot for your help fellas

  5. #5
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Pretty basic java program..need some help!

    Read the 2nd reply to your thread and you will get your answer. See that carefully.

  6. #6
    Junior Member
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Pretty basic java program..need some help!

    hey fellas thanks a lot for your time and help. i got up and running!

  7. #7
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Pretty basic java program..need some help!

    Quote Originally Posted by LAerving View Post
    hey fellas thanks a lot for your time and help. i got up and running!
    Mark this thread as SOLVED.

Similar Threads

  1. [SOLVED] Basic Java Program Help
    By Nuggets in forum Java Theory & Questions
    Replies: 15
    Last Post: January 18th, 2012, 12:47 AM
  2. Re: Basic Java Program Help
    By Tanushri in forum Java Theory & Questions
    Replies: 3
    Last Post: January 18th, 2012, 12:43 AM
  3. Not sure what to do next (Basic java program)
    By desi22601 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 21st, 2010, 09:05 AM
  4. Pretty new to Java can someone help with an addObject() problem?
    By alan120184 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 1st, 2009, 12:48 PM
  5. Basic Java Program Help
    By roaster in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 6th, 2009, 10:28 PM