SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 304 Weeks Ago, 3 Days Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 07 Jan 2018 My Price 10.00

public class BookCentre extends JApplet implements

Can you please check what's wrong with the BookCentre program, thank you.

  • import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class BookCentre extends JApplet implements ActionListener, ItemListener
    {
        private CardLayout cardManager;
        private JPanel deck;
        private JButton controls[];
        private String names[] = {"Input", "Processing", "Display"};
        //card 1
        private JTextField T1 = new JTextField ();
        private JLabel label2 = new JLabel ("");
        private JButton Button1 = new JButton ("Submit");
        private String Name1[] = {"Deitel-Java How to Program", "Horstmann-Big Java", "Lewis-Software Solutions",
        "Staugaard-Java for IS", "Sun-Core Java", "Hamilton-JDBC", "Jackson-Java By Example", "Riley-The Object of Java",
        "Geary-Graphic Java", "Santry-Advanced Java2", "Bishop-Java Gently", "Wigglesworth-Advanced Java",
        "Liang-Intro to Java", "Lambert-Java"};
        private JList List1 = new JList (Name1);

        //card 2
        private JPanel card2 = new JPanel ();
        private JComboBox custList = new JComboBox ();
        private JLabel label3 = new JLabel ("");
        private JButton Button2 = new JButton ("Submit");

        private ButtonGroup radioGroup[] = new ButtonGroup [3];
        private JRadioButton accept[] = new JRadioButton [3];
        private JRadioButton reject[] = new JRadioButton [3];
        private JLabel label4[] = new JLabel [3];

        //card 3
        private JPanel card3 = new JPanel ();
        private JTextArea custText = new JTextArea ();

        private static int INDEX = 0;
        private static final int MAX = 100;
        private Customer customer[] = new Customer [MAX];

        // set up GUI
        public void init ()
        {
        Container container = getContentPane ();
        // create the JPanel with CardLayout
        deck = new JPanel ();
        cardManager = new CardLayout ();
        deck.setLayout (cardManager);

        // add cards to JPanel deck
        deck.add (card1Panel (), "c1");
        deck.add (card2Panel (), "c2");
        deck.add (card3Panel (), "c3");

        // create and layout buttons that will control deck
        JPanel buttons = new JPanel ();
        buttons.setLayout (new GridLayout (3, 1));
        controls = new JButton [names.length];

        for (int count = 0 ; count < controls.length ; count++)
        {
            controls [count] = new JButton (names [count]);
            controls [count].addActionListener (this);
            buttons.add (controls [count]);
        }
        // add JPanel deck and JPanel buttons to the applet
        container.add (buttons, BorderLayout.WEST);
        container.add (deck, BorderLayout.EAST);
        setSize (700, 500);
        setVisible (true);
        } // end constructor


        public JPanel card1Panel ()
        {
        JLabel label6 = new JLabel ("Enter Customer Information", SwingConstants.CENTER);
        JLabel label1 = new JLabel ("Customer Name:", SwingConstants.LEFT);
        JLabel label7 = new JLabel ("Choose exactly three books:(use CTRL or SHIFT)", SwingConstants.LEFT);
        JPanel card1 = new JPanel ();

        List1.setVisibleRowCount (10);
        List1.setSelectionMode (ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

        JPanel topPanel = new JPanel ();
        topPanel.setLayout (new GridLayout (5, 1));
        topPanel.add (label6);
        topPanel.add (label2);
        topPanel.add (label1);
        topPanel.add (T1);
        topPanel.add (label7);

        card1.setLayout (new BorderLayout (20, 20));
        card1.add (topPanel, BorderLayout.NORTH);
        card1.add (new JScrollPane (List1), BorderLayout.CENTER);
        card1.add (Button1, BorderLayout.SOUTH);

        Button1.addActionListener (this);
        return card1;
        }


        public JPanel card2Panel ()
        {
        JLabel label2 = new JLabel ("Processing", SwingConstants.CENTER);
        JPanel subPanel = new JPanel ();
        subPanel.setLayout (new GridLayout (2, 1));
        subPanel.add (label2);
        subPanel.add (custList);

        JPanel subPanel2 = new JPanel ();
        subPanel2.setLayout (new GridLayout (3, 3));

        for (int j = 0 ; j < 3 ; j++)
        {
            radioGroup [j] = new ButtonGroup ();
            accept [j] = new JRadioButton ("Can be shipped ", false);
            reject [j] = new JRadioButton ("Shipment delayed ", true);
            label4 [j] = new JLabel ("Book " + (j + 1));
            radioGroup [j].add (accept [j]);
            radioGroup [j].add (reject [j]);
            subPanel2.add (accept [j]);
            subPanel2.add (reject [j]);
        }

        JPanel subPanel3 = new JPanel ();
        subPanel3.setLayout (new GridLayout (1, 1));
        subPanel3.add (Button2);

        card2.setLayout (new BorderLayout (20, 20));
        card2.add (subPanel, BorderLayout.NORTH);
        card2.add (subPanel2, BorderLayout.CENTER);
        card2.add (subPanel3, BorderLayout.SOUTH);

        Button2.addActionListener (this);
        custList.addItemListener (this);
        return card2;
        }


        public JPanel card3Panel ()
        {
        JLabel label8 = new JLabel ("List of Customers and Order Status...");

        JPanel topPanel = new JPanel ();
        //topPanel.setLayout(new GridLayout(1,1));
        topPanel.add (label8);

        card3.add (topPanel, BorderLayout.NORTH);
        card3.add (custText, BorderLayout.CENTER);
        custText.setFont (new Font ("Serif", Font.ITALIC, 12));
        return card3;
        }


        // handle button events by switching cards
        public void actionPerformed (ActionEvent event)
        {
        // show input
        if (event.getSource () == controls [0])
            cardManager.first (deck);

        // show processing
        else if (event.getSource () == controls [1])
        {

            custList.removeAllItems ();
            label3.setText ("");

            for (int i = 0 ; i custList.addItem (customer [i]) ;
        }
        cardManager.show (deck, "c2") ;

            // show display
        }


        else if (event.getSource () == controls [2])
        {
        custText.setText ("");
        // Bubble Sort
        int i, j;
        Customer tmp;
        for (i = 0 ; i for (j = 0 ; j if (customer [j + 1].getName ().compareTo (customer [j].getName ()) < 0)
                {
                tmp = customer [j];
                customer [j] = customer [j + 1];
                customer [j + 1] = tmp;
                }
        }


        for (i = 0 ; i custText.append (customer [i].toString () + "\n") ;
    }
    cardManager.last (deck) ;
    }
    else if (event.getSource () == Button1)
    {

        String str = "";
        String cusName = T1.getText ().toUpperCase ();

        boolean go = true;
        int listIndex[] = List1.getSelectedIndices ();

        if (T1.getText ().equals (""))
        {
        str = "Error: Please enter your name.";
        go = false;
        }


        else if (listIndex.length != 3)
        {
        str = "Error: Please select 3 books.";
        go = false;
        }


        if (go)
        {
        str = cusName + " : You are the customer #" + (INDEX + 1) + " out of 100.";
        List1.clearSelection ();
        T1.setText ("");
        //new customer here
        if (INDEX <= MAX)
        {
            String book0 = List1.getModel ().getElementAt (listIndex [0]).toString ();
            String book1 = List1.getModel ().getElementAt (listIndex [1]).toString ();
            String book2 = List1.getModel ().getElementAt (listIndex [2]).toString ();
            customer [INDEX] = new Customer (cusName, book0, book1, book2);
            INDEX++;
        }
        else
        {
            str = cusName + "Sorry, no more new customers.";
        }
        }


        label2.setText (str);
    }
    else if (event.getSource () == Button2)
    {
        try
        {
        Customer custCurr = (Customer) custList.getSelectedItem ();
        for (int j = 0 ; j < 3 ; j++)
        {
            if (reject [j].isSelected ()) //check if radio is clicked
            custCurr.removeShipment (j);
            else
            custCurr.setShipment (j);
        }
        //reset the radio when submitted
        for (int j = 0 ; j < 3 ; j++)
        {
            reject [j].setSelected (true);
        }
        }


        catch (Exception ex)
        {
        }
    }
    }
    // handle radio button events
    public void itemStateChanged (ItemEvent event)
    {
        if (event.getStateChange () == ItemEvent.SELECTED)
        {
        Customer custCurr = (Customer) custList.getSelectedItem ();
        for (int i = 0 ; i < 3 ; i++)
        {
            label4 [i].setText (custCurr.getBook (i));
        }
        }
    }
    } // end class BookCentre

    class Customer {
        private String name;
        private String book0;
        private String book1;
        private String book2;
        private boolean accept0;
        private boolean accept1;
        private boolean accept2;

     
        public Customer (String n, String u0, String u1, String u2){
            name=n;
            book0=u0;
            book1=u1;
            book2=u2;
            accept0=accept1=accept2=false;
        }
     
        public void setShipment(int which){
            switch(which){
                case 0: accept0=true; break;
                case 1: accept1=true; break;
                case 2: accept2=true; break;
            }
        }


        public void removeShipment(int which){
             switch(which){
                case 0: accept0=false; break;
                case 1: accept1=false; break;
                case 2: accept2=false; break;
            }
        }

     
        public boolean getShipment(int which){
            switch(which){
                case 0: return accept0;
                case 1: return accept1;
                case 2: return accept2;
                default : return false;
            }
        }

        public String getBook(int which){
            switch(which){
                case 0: return book0;
                case 1: return book1;
                case 2: return book2;
                default : return "Invalid";
            }
        }
       
        public String getName(){
           return name;
        }   

        public String toString(){
            String result = name + "\n";
            result += book0;

            if (accept0) result += " - shipped\n";
            else result += " - delayed\n";
            result += book1;

            if (accept1) result += " - shipped\n";
            else result += " - delayed\n";
            result += book2;

            if (accept2) result += " - shipped\n";
            else result += " - delayed\n";

            return result;
        }
    }



Attachments:

Answers

(5)
Status NEW Posted 07 Jan 2018 12:01 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)