After reviewing this chapter, you feel much more comfortable with classes but yo
ID: 3604278 • Letter: A
Question
After reviewing this chapter, you feel much more comfortable with classes but you now need create your own class objects. One “thing” which seems to be prevalent in all of the applications run from the moose skateboards web site is a Skateboard.
You have decided to consolidate all of the data and modules involved with skateboards and build a class file to be used with other applications. For this case study you’ll need a design class file itself along with the driver (application logic) class to test the code within the class.
.Create the pseudo-code that will hold the following data elements along with accessor in mutator methods.
.skateboard model number
.skateboard color
.skateboard serial number
.skateboard cost
.skateboard price
.After the class called Skateboard create an app to print the serial number and model number a sales summary showing the price, cost and the calculated profit (Price - Cost).
Explanation / Answer
ANSWER::
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
public class DeckPanel extends JPanel implements ListSelectionListener
{
private JPanel deckPanel;
private JList deckList;
String[] decks = {"The Master Trasher" , "The Dictator", "The Street King"};
public DeckPanel()
{
deckList = new JList(decks);
add(deckList);
JScrollPane scrollbar = new JScrollPane(deckList);
scrollbar.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollbar.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
add(scrollbar);
deckList.setVisibleRowCount(2);
deckList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
deckList.addListSelectionListener(this);
setLayout(new GridLayout(3, 1));
}
public void valueChanged(ListSelectionEvent e)
{
if (!e.getValueIsAdjusting()){
String selection = (String) deckList.getSelectedValue();
System.out.println(selection);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.