using inheritance in java write the following classes and a test class sedan cla
ID: 3610186 • Letter: U
Question
using inheritance in javawrite the following classes and a test class
sedan class
data fields (all are private): weight,double
color, string
make, string
model, string
price, double
discount, double
get set for each data fields
price is initialized to $15,000 discount is 2% of price plus$500
ford focus class dodge calibreclass
price: $13,000 price :$17,000
discount: 5% ofprice discount:$1,000
in test class, created objects of ford focus and dodge calibre.printout all their data fields.
***we have to use set and get***
Explanation / Answer
Dear... import javax.swing.*;import java.awt.*;
import javax.swing.JOptionPane;
import java.awt.event.*;
class sedan extends price implements ActionListener
{
JLabel numberLabel, numberLabel2;
JTextField numberPriceField, numberDiscountField;
JButton displayButton;
public sedan() { priate stringcolor; priate stringmake; priate stringmodel; Container pane =getContentPane();
pane.setLayout(new GridLayout (3,2, 2, 2));
numberLabel = new JLabel ("Price:");
numberPriceField = new JTextField(10);
numberLabel2 = newJLabel("Discount");
numberDiscountField = newJTextField (10);
displayButton = new JButton("Calculate");
pane.add(numberLabel);
pane.add(numberPriceField);
pane.add(numberLabel2);
pane.add(numberDiscountField);
pane.add(displayButton);
displayButton.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle ("CALCULATEPRICE AFTER DISCOUNT");
pack();
show();
}
public static void main (String[] args) {
new sedan();
}
public void actionPerformed(ActionEventevent) {
Object source = event.getSource();
if (source ==displayButton) {
try {
double price =Double.parseDouble(numberPriceField.getText());
double discount =Double.parseDouble(numberDiscountField.getText());
doubleresult =price-((discount/100)*price);
JOptionPane.showMessageDialog(null,"Price after discount is " +(result); System.exit(0); }
catch (Exception e) {
JOptionPane.showMessageDialog(null, "You have entered an invalidvalue.",
JOptionPane.PLAIN_MESSAGE);
}
}
}
} I hope it is useful toyou.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.