Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/Debugged, Joyce Farrell, Java Programming, Chapter 10 // need to be fixed, ther

ID: 3668291 • Letter: #

Question

/Debugged, Joyce Farrell, Java Programming, Chapter 10

// need to be fixed, there is error when u run the java.

//there are 2 class below

1 // A PhoneBook is a Book with a city
2 import javax.swing.*;
3 public class DebugTen3
4 {
5 public static void main(String[] args)
6 {
7 String area, inStr;
8 int pages;
9 area = JOptionPane.showInputDialog(null,
10 "Enter city for phone book");
11 inStr = JOptionPane.showInputDialog(null,
12 "Enter number of pages in " + area + "'s phone book");
13 pages = Integer.parseInt(inStr);
14 DebugPhoneBook pb = new DebugPhoneBook();
15 pb.display();
16 }
17 }

-------------------------------------------------------------

// class for DebugTen3

1 import javax.swing.*;
2 public class DebugPhoneBook extends DebugBook
3 {
4 private String area
5 private String size
6 private final int CUTOFF = 30;
7 FixDebugPhoneBook(int pages, int city)
8 {
9 super(pages);
10 area = city;
11 if(pages < CUTOFF)
12 size = "big";
13 else
14 size = "small";
15 }
16 public void display()
17 {
18 JOptionPane.showMessageDialog(null,"The phone book for " + area +
19 " has " + pages + " pages. That is a " +
20 size + " phone book.");
21 }
22 }

----------------------------------------------------------

//class for DebugTen3

1 public class DebugBook
2 {
3 protected int pages;
4 public void DebugBook(int pgs)
5 {
6 pages = pgs;
7 }
8 public int getPages()
9 {
10 return pgs;
11 }
12 }

Explanation / Answer

Hi, I have fixed the issue. Now working fine.

import javax.swing.*;
public class DebugTen3
{
   public static void main(String[] args)
   {
       String area, inStr;
       int pages;
       area = JOptionPane.showInputDialog(null,
               "Enter city for phone book");
       inStr = JOptionPane.showInputDialog(null,
               "Enter number of pages in " + area + "'s phone book");
       pages = Integer.parseInt(inStr);
       DebugPhoneBook pb = new DebugPhoneBook(pages,area);
       pb.display();
   }
}

class DebugPhoneBook extends DebugBook
{
   private String area;
   private String size;
   private final int CUTOFF =30 ;
   public DebugPhoneBook(int pages, String city)
   {
       super(pages);
       area = city;
       if(pages < CUTOFF)
           size = "big";
       else
           size = "small";
   }
   public void display()
   {
       JOptionPane.showMessageDialog(null,"The phone book for " + area +
               " has " + pages + " pages. That is a " +
               size + " phone book.");
   }
}
class DebugBook
{
   protected int pages;
   public DebugBook(int pgs)
   {
       pages = pgs;
   }
   public int getPages()
   {
       return pages;
   }
}