Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Pizza {
- char size; //the values could be: L, M, or S (only capital letters)
- char type; //the values could be: T for thin, or P for pan.
- int toppings;
- double price;
- double calculatePrice(){
- System.out.println("The program is now calculating the price of this pizza");
- price = 0;
- if(size =='L'){
- price = 3 + toppings * 0.5;
- }else if(size == 'M'){
- price = 2 + toppings * 0.4;
- }else if(size == 'S'){
- price = 1 + toppings * 0.25;
- }else{
- System.out.println("Wrong size");
- System.exit(0);
- }
- if(type == 'P' || type == 'p'){
- price = price +1;
- }
- return price;
- }
- boolean hasResonablePrice(){
- System.out.println("The program is now checking if the price is reasonable");
- boolean reasonable = false;
- if(toppings >5){
- if((size=='L' && price <7)||((size=='M' || size=='S')&& price <5) ){
- reasonable = true; }
- else{
- reasonable = false;}
- }
- else if (toppings <=5 && type != 'P'){
- if( price<5){
- reasonable = true; }
- else{
- reasonable = false;}
- }
- else if(price < 4){
- reasonable = true;
- }
- else{
- reasonable = false;
- }
- return reasonable;
- }
- boolean isMoreExpensiveThan (double money){
- boolean comparePrice;
- if(price>money){
- comparePrice = true;
- }
- else{
- comparePrice = false;
- }
- return comparePrice;
- }
- public String toString(){
- String details = "the size: "+size+",the type: "+type+", number of toppings: "+toppings+", price: "+price;
- return details;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement