Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class a3_18srs {
- public static void main (String[] args) {
- Pizza sPizza = new Pizza("small", "double", true, true, true);
- Pizza mPizza = new Pizza("medium", "triple", true, true, false);
- System.out.println(sPizza.toString());
- System.out.println(mPizza.toString());
- System.out.println(sPizza.isEquals(mPizza));
- }
- static class Pizza {
- private String size;
- private String cheese;
- private boolean papple;
- private boolean gpepper;
- private boolean ham;
- private double price;
- public Pizza(String size, String cheese, boolean papple, boolean gpepper, boolean ham){
- this.size = size;
- this.cheese = cheese;
- this.papple = checkPaGp();
- this.gpepper = checkPaGp();
- this.ham = ham;
- this.price = fioCost();
- }
- public String toString(){
- String rS = size + " pizza, " + cheese + " cheese. Cost: $" + String.format("%.2f",price) + " each.";
- return rS;
- }
- public double getCost(){
- return price;
- }
- public boolean isEquals(Pizza p){
- boolean x = p instanceof Pizza;
- return x;
- }
- public double fioCost(){
- double cost = 0.0;
- if(this.size == "small"){
- cost+= 7.00;
- }
- else if(this.size == "medium"){
- cost+= 9.00;
- }else{
- cost+= 11.00;
- }
- if(ham){
- cost+=1.50;
- }
- else if(gpepper){
- cost+=1.50;
- }
- else if(papple){
- cost+=1.50;
- }
- return cost;
- }
- public boolean checkPaGp(){
- if(!ham){
- return false;
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement