Last active
October 27, 2022 01:27
-
-
Save saiccoumar/7d8ca61352ce0cf3f48e326a3a81cfd6 to your computer and use it in GitHub Desktop.
Object Oriented Programming Dummy Code
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
//Imagine these variables are publicly accessible or getters exist and I'm using those | |
public Fruit(String name, String color, String taste, boolean healthy, int size, float calories) { | |
this.name = name; | |
this.color = color; | |
this.taste = taste; | |
this.healthy = healthy; | |
this.size = size; | |
this.calories = calories; | |
} | |
public void identify(Fruit fruit) { | |
System.out.println("The fruit is " + fruit.getName() + ". It's " + fruit.getColor() + " and it tastes " + fruit.getTaste()); | |
} | |
public void stats(Fruit fruit) { | |
System.out.println("The " + fruit.getName() + " has a size of " + fruit.getSize() + " and it has " + fruit.getCalories() + "."); | |
} | |
public boolean isApple(Fruit fruit) { | |
if (fruit.getName().equals("apple")){ | |
return True; | |
} | |
return False; | |
} | |
Fruit apple = Fruit("apple","red","good", True, 4, 150); | |
identify(apple; | |
stats(apple); | |
System.out.println(isApple(apple)); |
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
public void identify(String name, String color, String taste, boolean healthy, int size, float calories) { | |
System.out.println("The fruit is " + name + ". It's " + color + " and it tastes " + taste); | |
} | |
public void stats(String name, String color, String taste, boolean healthy, int size, float calories) { | |
System.out.println("The " + name + " has a size of " + size + " and it has " + calories + "."); | |
} | |
public boolean isApple(String name, String color, String taste, boolean healthy, int size, float calories) { | |
if (name.equals("apple")){ | |
return True; | |
} | |
return False; | |
} | |
identify("apple","red","good", True, 4, 150); | |
stats("apple","red","good", True, 4, 150); | |
System.out.println(isApple("apple","red","good", True, 4, 150)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment