Created
November 11, 2015 05:25
-
-
Save golenishchev/c7ab1f3eb1d0ae89d9a9 to your computer and use it in GitHub Desktop.
Lesson 5. Constructor, object, toString
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Computer { // Creating class Computer | |
int powerSupply; // fields | |
float processor; | |
int videoCard; | |
int primaryStorageRam; | |
int secondaryStorageHdd; | |
String motherBoard; | |
float water; // water coolled processor and video card | |
public Computer(int powerSupply, float processor, int videoCard, int primaryStorageRam, int secondaryStorageHdd, String motherBoard, float water) { // constructor | |
this.powerSupply=powerSupply; | |
this.processor=processor; | |
this.videoCard=videoCard; | |
this.primaryStorageRam=primaryStorageRam; | |
this.secondaryStorageHdd=secondaryStorageHdd; | |
this.motherBoard=motherBoard; | |
this.water=water; | |
} | |
public String toString() { // overriding the default Object toString() method | |
return "All values of MyComp object: " + "\npowerSupply=" + powerSupply + "\nprocessor=" + processor + "\nvideoCard=" + videoCard + "\nprimaryStorageRam=" + primaryStorageRam + "\nsecondaryStorageHdd=" + secondaryStorageHdd + "\nmotherBoard=" + motherBoard + "\nwater=" + water; | |
} | |
public static void main(String[] args) { | |
Computer myComp = new Computer(450, 2.4f, 11, 4, 500, "Asus P5K", 1.f); // object myComp. Dont know where it's propper place | |
System.out.println("" + myComp.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment