The errors are within the main class at the bottom, I have them detailed within the code along with their error messages. I also have a super() keyword in my Session constructor to call methods from the Customer class. I just want to run my program but every time I fix one issue another one (or two) takes its place. Please help!
import java.util.*;
public class Main
{
public class Customer
{
public String Name = "";
public int ID = 0000;
public int plansLeft = 0;
public Customer()
{
}
public Customer (String n, int id, int pl)
{
Name = n;
ID = id;
plansLeft = pl;
}
public void setName(String n)
{
Name = n;
}
public void setidnumber(int id)
{
ID = id;
}
public void setPlansLeft(int pl)
{
plansLeft = pl;
}
public String getName()
{
return Name;
}
public int getIDNumber()
{
return ID;
}
public int getPlansLeft()
{
return plansLeft;
}
}
public class Session extends Customer
{
public int sessionIDNumber = 0000;
public int spotsLeft = 0;
public Session()
{
}
public Session (String Name, int ID, int plansLeft, int sID, int sl)
{
super(Name, ID, plansLeft); // <----- perhaps an issue here?
sessionIDNumber = sID;
spotsLeft = sl;
}
public int getsessionIDNumber() {
return sessionIDNumber;
}
public int getspotsLeft() {
return spotsLeft;
}
public void setsessionIDNumber(int sessionIDNumber) {
this.sessionIDNumber = sessionIDNumber;
}
public void setspotsLeft(int sl) {
this.spotsLeft = sl;
}
}
public static void main(String[] args)
{
//public Customer(){} // <----- tried using this but only adds more errors
Customer customer = new Customer("Sarah", 12345678, 12, 0117, 0); // < ----- error is here: "The constructor Main.Customer(String, int, int, int, int) is undefined"
System.out.println("Customer Name: " + customer.getName() + "\nCustomer ID: " + customer.getIDNumber() + "\nLessons Remaining: " + customer.getPlansLeft());
System.out.println("\nSession ID: " + customer.getsessionIDNumber() + "\nOpen Spots Available: " + customer.getspotsLeft()); // < ------ couple more errors here: "The method getsessionIDNumber/getspotsLeft() is undefined for the type Main.Customer"
}
}
One thing remember when you use inheritance always create object of child(sub) class. in your case, Session is sub class in which you have five parameters but you created Customer class which not have five parameters.
Customer customer = new Customer("Sarah", 12345678, 12, 0117, 0);
This line issue an error because Customer class do not have five parameters.
Customer and Session class both present in Main class so their object access through Main class object.
use below code instead of above-
Session session= new Main().new Session("Sarah", 12345678, 12, 0117, 0);
when child class object created it call parent class constructor also. and for your comment call everything using session object-
System.out.println("Customer Name: " + session.getName() + "\nCustomer ID: " + session.getIDNumber() + "\nLessons Remaining: " + session.getPlansLeft());
System.out.println("\nSession ID: " + session.getsessionIDNumber() + "\nOpen Spots Available: " + session.getspotsLeft());