Results 1 to 17 of 17
  1. #1
    shin777 is offline Member
    Join Date
    May 2013
    Posts
    43
    Rep Power
    0

    Default Did I get this right? using multiple method to get rates.

    Did I get this right? using multiple method to get rates.-2e4wwav.jpg

    This is instruction. As it says on there, I don't need to use multiple class but just 2 methods and I don't need to make result dialogbox look same as picture as long as it displays right result.
    Here's code I wrote. Did I get this right or did I do something wrong here? It displays right result but I am not so sure this is how I am suppose to do. I didn't put all comments yet but just
    basic calculation ones.

    Java Code:
    import javax.swing.JOptionPane;
    import java.text.DecimalFormat;
    import java.util.Scanner;
    
    public class Practice
    {
    	public static double calcExtraCost(double baseCost, double rate)
    	{
    		//calcuate tax
    		return (baseCost*rate);
    	}
    
    	public static void main(String[] args)
    	{
    		double diamondCost;
    		double settingCost;
    		int numOrdered;
    		double baseCost;
    		double totalCost;
    		double laborCost;
    		double stateTax;
    		double luxuryTax;
    		double finalAmountDue;
    		double luxuryRate;
    		double stateRate;
    		double laborRate;
    		
    		
    		
    		Scanner keyInput = new Scanner(System.in);
    		//get inputs
    		System.out.println("Enter diamond cost.");
    		diamondCost = keyInput.nextDouble();
    		System.out.println("Enter setting cost.");
    		settingCost = keyInput.nextDouble();
    		System.out.println("Enter number ordered.");
    		numOrdered = keyInput.nextInt();
    		
    		//get base cost and initialize rates
    		baseCost = (diamondCost+settingCost);
    		luxuryRate = 0.2; 
    		stateRate = 0.10;
    		laborRate = 0.05;
    		
    		
    		//get tax values
    		stateTax = calcExtraCost(baseCost, stateRate);
    		luxuryTax = calcExtraCost(baseCost, luxuryRate);
    		laborCost = calcExtraCost(baseCost, laborRate);
    		
    		//calculate total cost
    		totalCost = baseCost+stateTax+luxuryTax+laborCost;
    		
    		//get final price
    		finalAmountDue = totalCost*numOrdered;
    				
    		DecimalFormat formatter = new DecimalFormat("#0.00");
    		
    		//print out result in console
    		System.out.println("Jasmine Jewelry: TOTAL COST BREAKDOWN\n" + "\n" + "Diamond Cost: $" + formatter.format(diamondCost) +
    			"\n" + "Setting Cost: $" + formatter.format(settingCost) + "\n" + "State tax @ 10%: $" + formatter.format(stateTax) + 
    			"\n" + "Luxury tax @ 20%: $" + formatter.format(luxuryTax) + "\n" + "Labor Cost @ 5%: $" + formatter.format(laborCost) + 
    			"\n" + "Total Price each: $" + formatter.format(totalCost) + "\n" + "\n" +  "Number ordered: " + numOrdered + "\n" + "\n" 
    			+ "Total Amount Due: $" + formatter.format(finalAmountDue));		
    		
    		//print out result in dialog box.
    		JOptionPane.showMessageDialog(null, "Jasmine Jewelry: TOTAL COST BREAKDOWN\n" + "\n" + "Diamond Cost: $" + formatter.format(diamondCost) +
    			"\n" + "Setting Cost: $" + formatter.format(settingCost) + "\n" + "State tax @ 10%: $" + formatter.format(stateTax) + 
    			"\n" + "Luxury tax @ 20%: $" + formatter.format(luxuryTax) + "\n" + "Labor Cost @ 5%: $" + formatter.format(laborCost) + 
    			"\n" + "Total Price each: $" + formatter.format(totalCost) + "\n" + "\n" +  "Number ordered: " + numOrdered + "\n" + "\n" 
    			+ "Total Amount Due: $" + formatter.format(finalAmountDue));		
    
    
    	}
    }
    Last edited by shin777; 07-06-2013 at 02:13 AM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default Re: Did I get this right? using multiple method to get rates.

    Quote Originally Posted by shin777 View Post
    Did I get this right or did I do something wrong here? It displays right result but I am not so sure this is how I am suppose to do.
    Feeling uncertain? If your program displays the correct results for the example values, at least it is promising; try some other values and see if it displays the expected results too. Your program looks correct to me. For bonus points: those tax rates are given to you so you can make them private static final double xxxRate = ...; also read the API documentation for the JOptionPane class and see how you can add a title to that dialog box (see note #3)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    shin777 is offline Member
    Join Date
    May 2013
    Posts
    43
    Rep Power
    0

    Default Re: Did I get this right? using multiple method to get rates.

    Quote Originally Posted by JosAH View Post
    Feeling uncertain? If your program displays the correct results for the example values, at least it is promising; try some other values and see if it displays the expected results too. Your program looks correct to me. For bonus points: those tax rates are given to you so you can make them private static final double xxxRate = ...; also read the API documentation for the JOptionPane class and see how you can add a title to that dialog box (see note #3)

    kind regards,

    Jos
    yep. i tested multiple times and it provided right result. I would add extras if my professor allow me too but he always take out huge points if we put anything we haven't learned in class yet. for example, adding title in dialog
    box. we didn't learn in class yet. :(

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default Re: Did I get this right? using multiple method to get rates.

    Ok, leave out the title stuff and turn your program in; I'm sure you'll get a fine grade (after you've added the necessary comments); don't add useless comments telling in detail what the code does; e.g.

    Java Code:
    int i= 0; // set variable i to zero
    Everybody can see that variable i is set to zero; we don't need any comment like that for it. ;-) Add comments such as 'calculate the different taxes given the rates' etc.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Did I get this right? using multiple method to get rates.

    Note that when I was learning this stuff myself 200 years ago I added those frivolous comments myself - not as a proper addition to the code but to help myself "see the matrix" as it were. If the simplest statements are kind of mysterious when you're not used to it all yet.

    I would give a slightly alternate advice: do add those comments as you please, but remove them again before turning in the assignment.

  6. #6
    shin777 is offline Member
    Join Date
    May 2013
    Posts
    43
    Rep Power
    0

    Default Re: Did I get this right? using multiple method to get rates.

    ok.. what the heck.. my professor just gave me 50% for this assignment. This is his comment. "You provided the correct results. however, you missed the point of the assignment. The reason I gave this assignment was to assess your ability to use methods. I even gave you step by step instructions that would have led you to do so. As such, I'm left not being able to assess your capability of using methods."

    Did I NOT use method calcExtraCost to calculate each tax rate and my main method called calcExtraCost to calculate each tax rate and displayed correct result? So What the heck is this guy saying? He sounds like I did everything on main method only and ignored the fact I actually used calcExtraCost method to get each tax rate. Did I really mis-understood whole thing or is my professor just trying to screw me?

  7. #7
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    264
    Rep Power
    2

    Default Re: Did I get this right? using multiple method to get rates.

    After reading the assignment. The instructions are clear and strict as to how you are supposed to work and you followed them pretty much fully.
    and I don't see any suggestions like extensive method use or anything like that. So unless you were not instructed to create and use methods for the rest of the assignment (expect the one given)
    I can't understand your teacher's comments.

  8. #8
    shin777 is offline Member
    Join Date
    May 2013
    Posts
    43
    Rep Power
    0

    Default Re: Did I get this right? using multiple method to get rates.

    I am getting destroyed. >.<
    Last edited by shin777; 07-13-2013 at 11:47 PM.

  9. #9
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    264
    Rep Power
    2

    Default Re: Did I get this right? using multiple method to get rates.

    Grades matter little if you understood the material and are able to work properly, even if you are unlucky in this case. I don't know what GPA is and generally the marking system in your uni how it works, but if you grasp
    the basics no reason to drop it. In assignments I have had, nearly all teachers gave a huge freedom, and initiative and extra stuff mattered a lot in a positive way; especially in programming courses.

  10. #10
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Did I get this right? using multiple method to get rates.

    There is always one teacher that is an unfair d1ck. Luckily on my second return to school I knew how to deal with them. I got an assignment to do a game of memory. I went all out - Swing GUI, I ripped the cards from Microsoft Patience and used those for the game itself and I made it properly 2 player with managing of scores and what not. It looked and behaved beautiful.

    (info: Dutch grading system is from 1-10).

    What grade did I get? The guy was amazed by it and he gave it a 7 (should be similar to a C or something). So I asked him "so what's wrong with it then?" After a few moments of silence he said "Yeah nothing actually. Okay, you get a 10" (an A). It was basically the fact that I did it better than he could have done himself that made him grade it so low. All you have to do is put such a person on the spot and let him explain his reasoning. And then be lucky that the guy is at least ethical enough to admit he's wrong.

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default Re: Did I get this right? using multiple method to get rates.

    Big old frustration #2: my professor once gave me a 0 (on a scale 1-10 (also the Dutch grading system) becaus he couldn't read my handwriting (which still is worse than terrible); he told me that he didn't even attempt to read it; I told him it was unfair and insisted that he'd read and grade my exam. It was a terrible subject, 'complex function theory' and that professor was known for his 'walz lists', i.e. 1,2,3,1,2,3 (on that 1-10 scale). He finally gave me a 6 (just enough points) and I immediately dropped that darn subject. Sometimes I dream about it and wake up sweating ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Did I get this right? using multiple method to get rates.

    Quote Originally Posted by JosAH View Post
    because he couldn't read my handwriting (which still is worse than terrible);
    left-handed perhaps? I have/had the same problem :)

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default Re: Did I get this right? using multiple method to get rates.

    Quote Originally Posted by gimbal2 View Post
    left-handed perhaps? I have/had the same problem :)
    Yup, at junior high they wanted me to write right-handed, it was a disaster; they even started hitting me on the hands with a ruler (I went to school 2000 years ago). The result is that I have no handwriting at all ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  14. #14
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,900
    Rep Power
    5

    Default Re: Did I get this right? using multiple method to get rates.

    Neither do I and I was never brutalized like that (I only got that dumb question, "have you tried writing with your right hand?". Sigh.). All lefties are meant to be doctors, I'm sure of it. Our terrible, unreadable handwriting proves it.

  15. #15
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default Re: Did I get this right? using multiple method to get rates.

    Quote Originally Posted by gimbal2 View Post
    Neither do I and I was never brutalized like that (I only got that dumb question, "have you tried writing with your right hand?". Sigh.). All lefties are meant to be doctors, I'm sure of it. Our terrible, unreadable handwriting proves it.
    That brutalizing only lasted for a couple of weeks; that old (female) teacher kept on nagging about my 'naughty hand' and my 'good hand' and hitting me with that ruler until I started yelling and vomiting in the middle of the class room; I had it in control from then on ;-)

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  16. #16
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: Did I get this right? using multiple method to get rates.

    Quote Originally Posted by gimbal2 View Post
    All lefties are meant to be doctors, I'm sure of it.
    I'll have you know that in my school life I had neat, small but highly legible handwriting. It's the keyboard that killed my hands.

    And yes, I'm left handed too.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  17. #17
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,447
    Blog Entries
    7
    Rep Power
    20

    Default Re: Did I get this right? using multiple method to get rates.

    Quote Originally Posted by DarrylBurke View Post
    I'll have you know that in my school life I had neat, small but highly legible handwriting. It's the keyboard that killed my hands.

    And yes, I'm left handed too.
    We could have a club and a secret handshake ...

    kind regards,

    Jos (<-- general benevolent admiral an emperor for life of the secret left handed geniuses)
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Best Way to Run a method on multiple buttons
    By Dcalladi in forum New To Java
    Replies: 1
    Last Post: 11-07-2011, 03:45 AM
  2. multiple threads access the same method.
    By bhanu in forum New To Java
    Replies: 3
    Last Post: 02-16-2009, 06:54 AM
  3. hourly rates
    By silverglade in forum New To Java
    Replies: 3
    Last Post: 02-09-2009, 12:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •