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 2 of 2

Thread: Beginner trying to write Java code, has issue w/ printing result and 2 decimals

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Beginner trying to write Java code, has issue w/ printing result and 2 decimals

    I'm taking a Java class which I am really liking so far. So I have this problem I am working on now.

    A. Create a class name purchase. Each purchase. Contains an invoice number, amount of sale, and amount of sales tax. Include set methods for the invoice number and sale amount. Within the set() method for the sale amount, calculate the sales tax as 5% of the sale amount. Also include a display method that displays a purchase's details. Save the file as purchase.java

    The issue I am having is the other two methods are not printing (sale2 and sale3). then on top of that I cannot get the final price to print 2 decimal places. It does not seem double or int will work, so what other options do I have?

    Thanks for the ideas folks.

    public class Main {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args)
       {
            int invoice1 = 25;
    	int invoice2 = 28;
    	double amtSale1 = 18.99;
    	double amtSale2 = 39.59;
    	double amtSale3 = 75.89;
    	double tax = 1.05;
    	sale1 (invoice1, amtSale1, tax);
       }
        public static int sale1(int invoice1, double amtSale1, double tax)
       {
            double total = tax * amtSale1;
            System.out.println("The invoice number is " + invoice1 + ".  And the total with 5% tax is $" + total);
    	        double newAmount;
            	newAmount = total;
            	return (int) newAmount;
       }
        public static int sale2(int invoice2, double amtSale2, double tax)
       {
            double total = tax * amtSale2;
            System.out.println("The invoice number is " + invoice2 + ".  And the total with 5% tax is $" + total);
    	        double newAmount;
            	newAmount = total;
            	return (int) newAmount;
       }
        public static int sale3(int invoice3, double amtSale3, double tax)
       {
            double total = tax * amtSale3;
            System.out.println("The invoice number is " + invoice3 + ".  And the total with 5% tax is $" + total);
    	        double newAmount;
            	newAmount = total;
            	return (int) newAmount;
       }
    }
    Last edited by copeg; June 5th, 2011 at 11:07 AM.


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,097
    Thanks
    169
    Thanked 779 Times in 725 Posts
    Blog Entries
    5

    Default Re: Beginner trying to write Java code, has issue w/ printing result and 2 decimals

    The issue I am having is the other two methods are not printing (sale2 and sale3).
    They are never called...but I'd recommend reading your instructions one more time. "Create a class named Purchase". A bunch of static methods does not meet your requirements, and defeats the purpose of an object oriented language.

    Lastly, for future reference, please use the code tags.

Similar Threads

  1. Issue with beginner program
    By suxen in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 5th, 2011, 08:55 AM
  2. Convert Decimals to Octals using only If/Else
    By jcattau in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 9th, 2011, 11:58 AM
  3. Beginner - Help with my code.
    By eddross in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 12th, 2010, 09:30 AM
  4. Replies: 0
    Last Post: March 5th, 2010, 12:32 AM
  5. How can i write this in code?
    By Mr. steve in forum Java Theory & Questions
    Replies: 2
    Last Post: November 30th, 2009, 09:07 PM