Created
May 26, 2022 15:33
-
-
Save IacovColisnicenco/579902db547d509ab7aaebe02fe0f45d to your computer and use it in GitHub Desktop.
Simple example of java class for beginner
This file contains 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
import java.util. *; | |
public class MyClass { | |
public static void main(String args[]) { | |
class Customer { | |
int amountOfPurchases; | |
String name; | |
public boolean hasDiscount(){ | |
if(amountOfPurchases >= 1000){ | |
return true; | |
} else { | |
return false; | |
} | |
} | |
public void helloCustomer(){ | |
if(hasDiscount()){ | |
System.out.println("Hello "+ name + ", you have 30% discount!"); | |
}else{ | |
System.out.println("Hello "+ name); | |
} | |
} | |
} | |
Customer jack = new Customer(); | |
jack.amountOfPurchases = 1000; | |
jack.name = "Jack"; | |
Customer joe = new Customer(); | |
joe.amountOfPurchases = 700; | |
joe.name = "Joe"; | |
jack.helloCustomer(); | |
joe.helloCustomer(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment