i'm trying to make a printDetails(); method but i keep getting an error "NullPointerException"
the method is on class Customer on the second if condition i tried replacing the condition statements, and tried declaring the calculateTotalPrice(); as a variable, and tried else if but all didn't work
CODE
public class Main {
public static void main(String[] args) {
Studio studio1 = new Studio(1,2799,0.1);
Customer c1 = new Customer("02","Naif", studio1);
Suite suite1 = new Suite(1, 3200, "Free breakfast");
Customer c2 = new Customer("02", "Faisal", suite1);
c1.printDetails();
c2.printDetails();
the customer class
public void printDetails() {
if (studio.isEmpty()){
System.out.println("Customer '" + name + "' ID: " + id + ", Reserved a studio with a total of '" + studio.calculateTotalPrice()+ "'");
}
if (suite.isEmpty()){
System.out.println("Customer '" + name + "' ID: " + id + ", Reserved a suite with a VIP service of '" + suite.VIPServices+ "'");
}
}
the isEmpty() method:
public boolean isEmpty(){
return true;
}
EDIT:
i solved it using a flag
in customer class i added public int flag
and on first const flag =1
second const
flag =2
Aucun commentaire:
Enregistrer un commentaire