//Debugged, Joyce Farrell, Java Programming, Chapter 10 // need to be fixed //th
ID: 3668048 • Letter: #
Question
//Debugged, Joyce Farrell, Java Programming, Chapter 10
// need to be fixed
//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
DebugPhoneBook: Every declaration,initialization and assignment statement should end with a semicolon.In this class, method "FixDebugPhoneBook" should be of void return type and its parameters are in INT type.But These initialization statements are produces error because of type.
DebugBook Class:it should return pages not pgs.It doesnot contain parameterized constructor.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.