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

Debug help please. Please debug the following code to get it to work correctly.

ID: 3547982 • Letter: D

Question

Debug help please. Please debug the following code to get it to work correctly.


// Displays list of payment options

// - credit card, check or cash

// Displays fee for using each - 5%, 2% or 0%


import javax.swing.*;

import java.awt.*;

import java.awt.event.*;


public class DebugFOurteen2 extends JFrame implements ItemListener

{

FlowLayout flow = new FlowLayout();

JComboBox payMethod

JLabel payList = new JLabel("Pay List");

JTextField totFees = new JTextField(25);

String pctMsg = new String("per cent will be added to your bill");

int[] fees = {5, 2, 0};

int feePct = 0;

String output;

int fee = 0;

public DebugFourteen2()

{

super("Pay List");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLayout(flow)

payMethod.addItemLisener(this);

add(payList);

add(payMethod);

payMethod.addItem("Credit card");

payMethod.addItem("Check");

payMethod.addItem("Cash");

add(totFees);

}

public static void main(String[] arguments)

{

JFrame cframe = new DebugFourteen2();

cframe.setSize(350,150);

cframe.setVisible(true);

}

public void itemStateChanged()

{

Object source = list.getSource();

if(source = payMethod)

{

int fee = payMethod.getSelectedIndex();

feePct = fees[x];

output = feePct + " " + pctMsg;

totFees.setText(output);

}

}

}

Explanation / Answer

I have debugged the code and pasted the correct code below...

Thanks


Code :


package com.apple.csc;


//Displays list of payment options


//- credit card, check or cash


//Displays fee for using each - 5%, 2% or 0%


import javax.swing.*;


import java.awt.*;


import java.awt.event.*;


public class DebugFOurteen2 extends JFrame implements ItemListener


{

private static final long serialVersionUID = 1L;


FlowLayout flow = new FlowLayout();


JComboBox payMethod = new JComboBox();


JLabel payList = new JLabel("Pay List");


JTextField totFees = new JTextField(25);


String pctMsg = new String("per cent will be added to your bill");


int[] fees = { 5, 2, 0 };


int feePct = 0;


String output;


int fee = 0;


public DebugFOurteen2()


{


super("Pay List");


setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


setLayout(flow);


payMethod.addItemListener(this);


add(payList);


add(payMethod);


payMethod.addItem("Credit card");


payMethod.addItem("Check");


payMethod.addItem("Cash");


add(totFees);


}


public static void main(String[] arguments)


{


JFrame cframe = new DebugFOurteen2();


cframe.setSize(350, 150);


cframe.setVisible(true);


}


public void itemStateChanged(ItemEvent list)


{


Object source = list.getSource();


if (source == payMethod)


{


int fee = payMethod.getSelectedIndex();


feePct = fees[getX()];


output = feePct + " " + pctMsg;


totFees.setText(output);


}


}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote