[Solved] java programming exercise debug program [closed]


Swap the arguments to the phonebook constructor

public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            String area, inStr;  //there is no need of inStr as you are not using it so remove it if not used
            int pages;

            System.out.println("Please enter your city");
            area = input.nextLine();

            System.out.println("Please enter page number " + area + "'s phone book");
            pages = input.nextInt();

            PhoneBook phoneBook = new PhoneBook(pages,area); //swapp the argurments
              phoneBook.display(pages, area); //add arguments to this otherwise it will just show 0 
        }

And in your phonebook class add argument to super

    PhoneBook(int pages, String city) {
        super(pages);  // u can even remove this its not needed
        area = city;
        if (pages > 300) {
            size = "big";
        } else {
            size = "small";
        }

public void display(int pages,String area) {
    System.out.println( area + pages + size);
}
}

Now it will work

3

solved java programming exercise debug program [closed]