SHARE
TWEET

Untitled

a guest Jun 19th, 2017 48 in 19 hours
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class GSM{
  2.  
  3.       //Fields
  4.       private String model;
  5.       private String manufacturer;
  6.       private double price;
  7.       private String owner;
  8.       private BatteryCharacteristics battery;
  9.       private DisplayCharacteristics display;
  10.       private static GSM nokiaN95 = new GSM("N95","Nokia",55.75,"IvanSimeonov");
  11.  
  12.       //Constructor without Battery and Display Char..
  13.       public GSM(String model, String manufacturer, double price, String owner){
  14.         this(model,manufacturer,price,owner,null,null);
  15.       }
  16.  
  17.       //Constructor without owner
  18.       public GSM(String model, String manufacturer, double price, BatteryCharacteristics battery, DisplayCharacteristics display ){
  19.          this(model,manufacturer,price,null,battery,display);
  20.       }
  21.  
  22.       //Constructor without price
  23.       public GSM(String model, String manufacturer, String owner, BatteryCharacteristics battery, DisplayCharacteristics display ){
  24.          this(model,manufacturer,0.0,owner,battery,display);
  25.       }
  26.  
  27.       //Constructor
  28.       public GSM(String model, String manufacturer, double price, String owner,BatteryCharacteristics battery, DisplayCharacteristics display ){
  29.          this.model = model;
  30.          this.manufacturer = manufacturer;
  31.          this.price = price;
  32.          this.owner = owner;
  33.          this.battery = battery;
  34.          this.display = display;
  35.       }
  36.  
  37.       public void displayStatic(){
  38.         System.out.println("Nokia N95 Information: " + GSM.nokiaN95);
  39.       }
  40.  
  41.  
  42.  
  43.       public void printInfor(){
  44.         System.out.printf("The phone %s is manufactured by %s.\nHis owner is %s and he paid %.3f.\n",this.model,this.manufacturer,this.owner,this.price);
  45.         System.out.println("Battery char: " + this.battery + " and Display char: " + this.display);
  46.       }
  47.  
  48. }
  49.  
  50. class BatteryCharacteristics{
  51.  
  52.       //Fields
  53.       private String model;
  54.       private String manufacturer;
  55.       private int idleTime;
  56.       private double hoursTalk;
  57.  
  58.       //Constructor
  59.       public BatteryCharacteristics(String model, String manufacturer, int IdleTime, double hoursTalk){
  60.          this.model = model;
  61.          this.manufacturer = manufacturer;
  62.          this.idleTime = idleTime;
  63.          this.hoursTalk = hoursTalk;
  64.       }
  65. }
  66.  
  67. class DisplayCharacteristics{
  68.  
  69.       //Fields
  70.       private float size;
  71.       private int colours;
  72.  
  73.       //Constructor
  74.       public DisplayCharacteristics(float size, int colours){
  75.             this.size = size;
  76.             this.colours = colours;
  77.       }
  78. }
  79.  
  80. public class GSMTest{
  81.        public static void main(String[] args){
  82.         // GSM[] allPhones = new GSM[];
  83.  
  84.          GSM first = new GSM("Galaxy S7 Edge", "Samsung",1014.99, "Ivan");
  85.          first.printInfor();
  86.          System.out.println();
  87.  
  88.          GSM second = new GSM("Galaxy S7 Edge", "Samsung", 1014.99, "Dessi", new BatteryCharacteristics("xc5df","Alion",14,37.7), new
  89.          DisplayCharacteristics(5.8f,65000));
  90.          second.printInfor();
  91.  
  92. /*   The phone Galaxy S7 Edge is manufactured by Samsung.
  93.      His owner is Dessi and he paid 1014.990.
  94.      Battery char: BatteryCharacteristics@33909752 and Display char: DisplayCharacteristics@55f96302
  95. */
  96.          System.out.println();
  97.  
  98.          GSM third = new GSM("Iphone 6s", "Apple",1562.31, "Ilina");
  99.          third.printInfor();
  100.          System.out.println();
  101.  
  102.          GSM forth = new GSM("Plus One 2", "One",1251.21, "Tsvqtko");
  103.          forth.printInfor();
  104.          System.out.println();
  105.  
  106.          forth.displayStatic();
  107.          //Nokia N95 Information: GSM@3d4eac69
  108.          System.out.println();
  109.        }
  110. }
RAW Paste Data
Want to get better at Java?
Learn to code Java in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top