Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. public class Pizza {
  2. char size; //the values could be: L, M, or S (only capital letters)
  3. char type; //the values could be: T for thin, or P for pan.
  4. int toppings;
  5. double price;
  6.  
  7. double calculatePrice(){
  8. System.out.println("The program is now calculating the price of this pizza");
  9. price = 0;
  10. if(size =='L'){
  11. price = 3 + toppings * 0.5;
  12. }else if(size == 'M'){
  13. price = 2 + toppings * 0.4;
  14. }else if(size == 'S'){
  15. price = 1 + toppings * 0.25;
  16. }else{
  17. System.out.println("Wrong size");
  18. System.exit(0);
  19. }
  20. if(type == 'P' || type == 'p'){
  21. price = price +1;
  22. }
  23. return price;
  24. }
  25. boolean hasResonablePrice(){
  26. System.out.println("The program is now checking if the price is reasonable");
  27. boolean reasonable = false;
  28. if(toppings >5){
  29. if((size=='L' && price <7)||((size=='M' || size=='S')&& price <5) ){
  30. reasonable = true; }
  31. else{
  32. reasonable = false;}
  33. }
  34. else if (toppings <=5 && type != 'P'){
  35. if( price<5){
  36. reasonable = true; }
  37. else{
  38. reasonable = false;}
  39. }
  40. else if(price < 4){
  41. reasonable = true;
  42. }
  43. else{
  44. reasonable = false;
  45. }
  46. return reasonable;
  47. }
  48.  
  49. boolean isMoreExpensiveThan (double money){
  50. boolean comparePrice;
  51. if(price>money){
  52. comparePrice = true;
  53. }
  54. else{
  55. comparePrice = false;
  56. }
  57. return comparePrice;
  58. }
  59.  
  60. public String toString(){
  61. String details = "the size: "+size+",the type: "+type+", number of toppings: "+toppings+", price: "+price;
  62. return details;
  63. }
  64.  
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement