Question: Why do I not need to create a Carly object for the Carly class in the CarlyEventDemo class when I need to make an object

Why do I not need to create a Carly object for the Carly class in the CarlyEventDemo class when I need to make an object for the CarlyEvent class? Code below and any explanation would be greatly appreciated.
import java.util.Scanner;
public class Carly {
public static void main(String [] args){
//variable
int guests;
//CarlyEvent event = new CarlyEvent();
motto();
guests = numGuests();
price(guests);
}
public static int numGuests(){
//variable
int numOfGuests;
//Scanner
Scanner input = new Scanner(System.in);
System.out.println("How many people will be attending the event? ");
numOfGuests = input.nextInt();
return numOfGuests;
}
public static void motto(){
//motto
System.out.println("**************************************************");
System.out.println("**");
System.out.println("* Carly's makes the food that makes it a party. *");
System.out.println("**");
System.out.println("**************************************************");
}
public static void price(int guests){
int ticketCost =35;
int total;
total = guests * ticketCost;
System.out.println("You have "+ guests +" guests attending the event, thus the total price is $"+ total);
boolean largeEvent =(guests >=50);
System.out.println("Large event: "+ largeEvent);
}
public static String getEventNum(){
//variable
String eventNumber;
Scanner input = new Scanner(System.in);
System.out.println("What is the event number? ");
eventNumber = input.next();
return eventNumber;
}
}
public class CarlyEvent {
public final static int pricePerGuest =35;
public final static int largeGroup =50;
private String eventNum;
private int numGuest;
private int price;
//event number
public String getEventNumber(){//get
return eventNum;
}
public void setEventNumber(String eventNum){//set
this.eventNum = eventNum;
}
//guests
public int getGuest(){//get
return numGuest;
}
public void setGuest(int numGuest){//set
this.numGuest = numGuest;
price = numGuest * pricePerGuest;
}
public int getPrice(){//get
return price;
}
}
public class CarlyEventDemo {
public static void main(String [] args){
//variables
//int price;
int numOfGuests;
String eventNum;
//objects
CarlyEvent event = new CarlyEvent();
Carly.motto();
eventNum = Carly.getEventNum();
numOfGuests = Carly.numGuests();
Carly.price(numOfGuests);
event.setEventNumber(eventNum);
event.setGuest(numOfGuests);
System.out.println("Event number: "+ event.getEventNumber()+"
Number of guests: "+ event.getGuest());
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!