Advertisement
uriahheep

Untitled

Mar 27th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. public class Main {
  2.  
  3.     public static void main(String[] args) {
  4.         MobilePhone phone = new MobilePhone("200 grammes", 1500);
  5.  
  6.  
  7.         String parameters = phone.getParameters();
  8.         System.out.println(parameters);
  9.         phone.displayPrice ();
  10.         phone.lowerPrice ();
  11.         phone.higherPrice ( 500 );
  12.  
  13.  
  14.        
  15.  
  16.     }
  17.  
  18. }
  19.  
  20. class MobilePhone {
  21.     String weight;
  22.     int price;
  23.  
  24.     public MobilePhone ( String weight, int price ) {
  25.         this.weight = weight;
  26.         this.price = price;
  27.     }
  28.  
  29.     public void displayValues ( ) {
  30.         System.out.println ( this.weight + " " + this.price );
  31.     }
  32.  
  33.     public String getParameters ( ) {
  34.         return "This phone weights " + this.weight + ", and it's nominal price is " + this.price;
  35.     }
  36.  
  37.     public void displayPrice ( ) {
  38.         System.out.println("This phone's price is " + this.price + "zł");
  39.     }
  40.     public void lowerPrice ( ) {
  41.         int percent = (this.price * 10) / 100;
  42.         this.price = (this.price - percent);
  43.         System.out.println ("\n\n ***SPECIAL OFFER!!***\n\n BUY TODAY " +
  44.         "AND SAVE 10% OF IT'S PRICE!!! \n\n " + this.price + "zł" +
  45.         "\n\nSEE HOW MUCH YOU SAVE!!" );
  46.     }
  47.     public void higherPrice (int a){
  48.         int x = this.price + a;
  49.         System.out.println ("****LAST CHANCE!! TOMORROW THE PRICE WILL SKYROCKET TO****\n\n" + x);
  50.     }
  51.  
  52.  
  53.  
  54.  
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement