Skip to content

Instantly share code, notes, and snippets.

@IacovColisnicenco
Created May 26, 2022 15:33
Show Gist options
  • Save IacovColisnicenco/579902db547d509ab7aaebe02fe0f45d to your computer and use it in GitHub Desktop.
Save IacovColisnicenco/579902db547d509ab7aaebe02fe0f45d to your computer and use it in GitHub Desktop.
Simple example of java class for beginner
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