943,573 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 3007
  • Java RSS
Aug 26th, 2008
0

book class

Expand Post »
java Syntax (Toggle Plain Text)
  1. public class book {
  2. private double basePrice = 0;
  3. private double vat = 0;
  4. private double discount = 0;
  5. private double sellPrice;
  6.  
  7. public book() {
  8. setBasePrice(0);
  9. setVat(0);
  10. setDiscount(0);
  11. }
  12.  
  13. public book(double basePrice, double discount, double vat) {
  14. setBasePrice(basePrice);
  15. setVat(discount);
  16. setDiscount(vat);
  17. }
  18.  
  19. public double getBasePrice() {
  20. return basePrice;
  21. }
  22.  
  23. public void setBasePrice(double basePrice) {
  24. if (basePrice >= 0)
  25. this.basePrice = basePrice;
  26. setSellPrice();
  27. }
  28.  
  29. public double getVat() {
  30. return vat;
  31. }
  32.  
  33. public void setVat(double vat) {
  34. if (vat >= 0)
  35. this.vat = vat;
  36. setSellPrice();
  37. }
  38.  
  39. public double getDiscount() {
  40. return discount;
  41. }
  42.  
  43. public void setDiscount(double discount) {
  44. if (discount >= 0)
  45. this.discount = discount;
  46. setSellPrice();
  47. }
  48.  
  49. public double getSellPrice() {
  50. return sellPrice;
  51. }
  52.  
  53. private void setSellPrice() {
  54. sellPrice = basePrice * ((100 + (vat - discount)) / 100);
  55. }
  56.  
  57. }
Similar Threads
Reputation Points: 8
Solved Threads: 0
Newbie Poster
rs_java is offline Offline
8 posts
since Aug 2008
Aug 26th, 2008
0

Re: book class

It looks OK. What is your problem?
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,258 posts
since Dec 2007
Aug 26th, 2008
0

Re: book class

java Syntax (Toggle Plain Text)
  1. package com.bookPortal.model;
  2.  
  3. public class Book {
  4. private double basePrice = 0;
  5. private int vat = 0;
  6. private int discount = 0;
  7. private double sellPrice;
  8.  
  9. public Book() {
  10. setBasePrice(0);
  11. setVat(0);
  12. setDiscount(0);
  13. }
  14.  
  15. public Book(double basePrice, int discount, int vat) {
  16. setBasePrice(basePrice);
  17. setVat(discount);
  18. setDiscount(vat);
  19. }
  20.  
  21. public double getBasePrice() {
  22. return basePrice;
  23. }
  24.  
  25. public void setBasePrice(double basePrice) {
  26. if (basePrice >= 0)
  27. this.basePrice = basePrice;
  28. setSellPrice();
  29. }
  30.  
  31. public int getVat() {
  32. return vat;
  33. }
  34.  
  35. public void setVat(int vat) {
  36. if (vat >= 0)
  37. this.vat = vat;
  38. setSellPrice();
  39. }
  40.  
  41. public int getDiscount() {
  42. return discount;
  43. }
  44.  
  45. public void setDiscount(int discount) {
  46. if (discount >= 0)
  47. this.discount = discount;
  48. setSellPrice();
  49. }
  50.  
  51. public double getSellPrice() {
  52. return sellPrice;
  53. }
  54.  
  55. private void setSellPrice() {
  56. sellPrice = basePrice * (100 + vat - discount) / 100;
  57. if (sellPrice < 0)
  58. sellPrice = 0;
  59. }
  60.  
  61. }



java Syntax (Toggle Plain Text)
  1. package com.bookPortal.modelTest;
  2.  
  3. import com.bookPortal.model.Book;
  4.  
  5. import junit.framework.TestCase;
  6.  
  7. public class BookTest extends TestCase{
  8. Book b = new Book();
  9.  
  10. public void testSetBasePrice(){
  11. b.setBasePrice(10);
  12. assertEquals(10.0, b.getBasePrice());
  13. }
  14. public void testWrongSetBasePrice(){
  15. b.setBasePrice(-10);
  16. assertEquals(0.0, b.getBasePrice());
  17. }
  18.  
  19. public void testSetVat(){
  20. b.setVat(10);
  21. assertEquals(10, b.getVat());
  22. }
  23. public void testWrongSetVat(){
  24. b.setVat(-10);
  25. assertEquals(0, b.getVat());
  26. }
  27.  
  28. public void testSetDiscount(){
  29. b.setDiscount(10);
  30. assertEquals(10, b.getDiscount());
  31. }
  32. public void testWrongSetDiscount(){
  33. b.setDiscount(-10);
  34. assertEquals(0, b.getDiscount());
  35. }
  36.  
  37. public void testSetSellPrice(){
  38. b.setBasePrice(10);
  39. b.setDiscount(0);
  40. b.setVat(18);
  41. assertEquals(11.80, b.getSellPrice());
  42. }
  43. public void testWrongSetSellPrice(){
  44. b.setBasePrice(0);
  45. b.setDiscount(50);
  46. b.setVat(18);
  47. assertEquals(0.0, b.getSellPrice());
  48. }
  49.  
  50. }

Tests successfull
Reputation Points: 8
Solved Threads: 0
Newbie Poster
rs_java is offline Offline
8 posts
since Aug 2008
Aug 26th, 2008
0

Re: book class

setVat(discount); setDiscount(vat);
Reputation Points: 8
Solved Threads: 0
Newbie Poster
rs_java is offline Offline
8 posts
since Aug 2008
Aug 26th, 2008
0

Re: book class

I am sure that someone, someday will understand what you are trying to tell us
Sponsor
Featured Poster
Reputation Points: 1014
Solved Threads: 446
Nearly a Senior Poster
javaAddict is offline Offline
3,258 posts
since Dec 2007
Aug 26th, 2008
0

Re: book class

so what a about the price
Reputation Points: 8
Solved Threads: 0
Newbie Poster
rs_java is offline Offline
8 posts
since Aug 2008
Aug 26th, 2008
0

Re: book class

product owner responsibility: Put into a simple list, typical product owner responsibilities are:

decide on the project vision - who is going to benefit from the project and how;
secure funding;
continuously make decisions on the product priorities - what is more important with the latest information in mind;
continuously make decisions on maximizing the product ROI - make sure the features with the biggest benefit/cost ratio are developed first.
Reputation Points: 8
Solved Threads: 0
Newbie Poster
rs_java is offline Offline
8 posts
since Aug 2008
Reputation Points: 8
Solved Threads: 0
Newbie Poster
rs_java is offline Offline
8 posts
since Aug 2008
Aug 26th, 2008
-1

Re: book class

XP Practices:
-Collective ownership
-coding standards
-sustainable pace
-test first
-acceptance tests
-automation
-onsite customer
-continuous integration
-pair programming
-metaphor
-refactoring
-incremental design
-stories
-small releases
-planning game
-informatie workspace
Reputation Points: 8
Solved Threads: 0
Newbie Poster
rs_java is offline Offline
8 posts
since Aug 2008
Aug 26th, 2008
0

Re: book class

Click to Expand / Collapse  Quote originally posted by rs_java ...
setVat(discount); setDiscount(vat);
Click to Expand / Collapse  Quote originally posted by rs_java ...
so what a about the price
Click to Expand / Collapse  Quote originally posted by rs_java ...
product owner responsibility: Put into a simple list, typical product owner responsibilities are:

decide on the project vision - who is going to benefit from the project and how;
secure funding;
continuously make decisions on the product priorities - what is more important with the latest information in mind;
continuously make decisions on maximizing the product ROI - make sure the features with the biggest benefit/cost ratio are developed first.
Click to Expand / Collapse  Quote originally posted by rs_java ...
XP Practices:
-Collective ownership
-coding standards
-sustainable pace
-test first
-acceptance tests
-automation
-onsite customer
-continuous integration
-pair programming
-metaphor
-refactoring
-incremental design
-stories
-small releases
-planning game
-informatie workspace
What am I thinking right now? You should be able to guess correctly because I have seen the proof of how advanced your website to user mind reading capabilities are.
Featured Poster
Reputation Points: 533
Solved Threads: 53
Senior Poster
jasimp is offline Offline
3,593 posts
since Aug 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: persistence: id of object not updated after em.persist(object)
Next Thread in Java Forum Timeline: Type mismatch: Cannot convert from void to double





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC