Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is quite different to your original implementation. But I believe it does what you want it to. There's probably a better way of implementing it, but I'm only implementing based on the information you've given me. Hope you understand it all...</p> <p><br/>UseCourse:</p> <pre><code>import javax.swing.JOptionPane; public class UseCourse { public UseCourse() { CollegeCourse college; // Collect all the necessary data first to determine whether it is a lab course or not. String dept = JOptionPane.showInputDialog(null, "Enter Department"); String courseNumString = JOptionPane.showInputDialog(null, "Enter Course Number"); int courseNum = Integer.parseInt(courseNumString); String credString = JOptionPane.showInputDialog(null, "Enter Credits"); int cred = Integer.parseInt(credString); // Now that we have the info we can ask the question. if (dept.equals("BIO") | dept.equals("CHM") | dept.equals("CIS") | dept.equals("PHY")) {college = new LabCourse(dept, courseNum, cred);} else {college = new LabCourse(dept, courseNum, cred);} college.display(); } public static void main(String[] args) {new UseCourse();} } </code></pre> <p>CollegeCourse:<Br></p> <pre><code>import javax.swing.JOptionPane; public class CollegeCourse { protected String dept; protected int courseNum; protected int cred; protected int fee; protected int Charge = 120; protected int labfee; public CollegeCourse(String dept, int courseNum, int cred) { this.dept = dept; this.courseNum = courseNum; this.cred = cred; fee = cred * Charge; } public void display(){ JOptionPane.showMessageDialog(null, dept + courseNum + "\nNon-lab Course" + "\n" + cred +" Credits" + "\nTotal fee is $" + fee); } } </code></pre> <p><br/>LabCourse:</p> <pre><code>import javax.swing.JOptionPane; public class LabCourse extends CollegeCourse { public LabCourse(String dept, int courseNum, int cred) {super(dept, courseNum, cred);} public void display() { fee += 50; JOptionPane.showMessageDialog(null, dept + courseNum + "\nLab Course" + "\n" + cred +" Credits" + "\nTotal fee is $" + fee); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload