Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. public class a3_18srs {
  2.  
  3. public static void main (String[] args) {
  4. Pizza sPizza = new Pizza("small", "double", true, true, true);
  5. Pizza mPizza = new Pizza("medium", "triple", true, true, false);
  6. System.out.println(sPizza.toString());
  7. System.out.println(mPizza.toString());
  8. System.out.println(sPizza.isEquals(mPizza));
  9. }
  10.  
  11. static class Pizza {
  12. private String size;
  13. private String cheese;
  14. private boolean papple;
  15. private boolean gpepper;
  16. private boolean ham;
  17. private double price;
  18.  
  19. public Pizza(String size, String cheese, boolean papple, boolean gpepper, boolean ham){
  20. this.size = size;
  21. this.cheese = cheese;
  22. this.papple = checkPaGp();
  23. this.gpepper = checkPaGp();
  24. this.ham = ham;
  25. this.price = fioCost();
  26. }
  27.  
  28. public String toString(){
  29. String rS = size + " pizza, " + cheese + " cheese. Cost: $" + String.format("%.2f",price) + " each.";
  30. return rS;
  31. }
  32. public double getCost(){
  33. return price;
  34. }
  35. public boolean isEquals(Pizza p){
  36. boolean x = p instanceof Pizza;
  37. return x;
  38. }
  39. public double fioCost(){
  40. double cost = 0.0;
  41. if(this.size == "small"){
  42. cost+= 7.00;
  43. }
  44. else if(this.size == "medium"){
  45. cost+= 9.00;
  46. }else{
  47. cost+= 11.00;
  48. }
  49.  
  50. if(ham){
  51. cost+=1.50;
  52. }
  53. else if(gpepper){
  54. cost+=1.50;
  55. }
  56. else if(papple){
  57. cost+=1.50;
  58. }
  59. return cost;
  60. }
  61. public boolean checkPaGp(){
  62. if(!ham){
  63. return false;
  64. }
  65. return true;
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement