Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By kammce

Thread: Assignment

  1. #1
    neowolf is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default Assignment

    I need this:
    "Field of Dreams Travel Agency has begun offering travel packages to baseball fans wanting to attend major league baseball games. The company offers a package allowing a fan to attend games in four cities of his or her choice, including transportation by car, tickets, lodging, and food. Assume that the fan lives in the city hosting one of the 30 major league baseball teams. The fan will travel from his or her home to the city of one of the teams of his choice, then will proceed to the city of one of the other teams and so on until all teams have been visited. Then, the fan will return home. Create a Java program that will compute the minimum cost of the trip. Your cost will be the cost of transportation (fuel cost per gallon/ miles per gallon * number of miles between ballparks), cost of tickets, cost of lodging, and cost of food. Ask the user his home city, which cities he wants to visit, the price of fuel, the fuel economy of his vehicle, the cost of lodging per day and the cost of food per day. Your program will compute the costs of all 24 possible routings and choose the minimum cost route. Mark up the minimum cost by 20% to arrive at the cost that will be quoted to the customer."

    And i have this:
    Java Code:
    package baseballapp;
    
    import java.awt.Dimension;
    import java.awt.Rectangle;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JOptionPane;
    
    public class Main extends JFrame {
        private String[] ComboC =
        { "Select One", "Anaheim", "Arizona (Phoenix)", "Atlanta", "Baltimore", "Boston", "Chicago", "Cincinnati",
          "Cleveland", "Colorado (Denver)", "Detroit", "Florida (Miami)", "Houston", "Kansas City", "Los Angeles",
          "Milwaukee", "Minnesota (Minneapolis)", "Montreal", "New York", "Oakland", "Philadelphia", "Pittsburgh",
          "San Diego", "San Francisco", "Seattle", "St. Louis", "Tampa Bay", "Texas (Arlington)", "Toronto" };
        String city1, city2, city3, city4;
        private JMenuBar menuBar = new JMenuBar();
        private JMenu menuFile = new JMenu();
        private JMenuItem menuFileExit = new JMenuItem();
        private JMenu menuHelp = new JMenu();
        private JMenuItem menuHelpAbout = new JMenuItem();
        private JComboBox jCBoxCity1 = new JComboBox(ComboC);
        private JLabel jLabel1 = new JLabel();
        private JLabel jLabel2 = new JLabel();
        private JComboBox jCBoxCity2 = new JComboBox(ComboC);
        private JLabel jLabel3 = new JLabel();
        private JComboBox jCBoxCity3 = new JComboBox(ComboC);
        private JLabel jLabel4 = new JLabel();
        private JComboBox jCBoxCity4 = new JComboBox(ComboC);
        private JButton jButton1 = new JButton();
        private JButton jButtonE = new JButton();
    
        public Main() {
            try {
                jbInit();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        private void jbInit() throws Exception {
            this.setJMenuBar(menuBar);
            this.getContentPane().setLayout(null);
            this.setSize(new Dimension(460, 345));
            menuFile.setText("File");
            menuFileExit.setText("Exit");
            menuFileExit.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    fileExit_ActionPerformed(ae);
                }
            });
            menuHelp.setText("Help");
            menuHelpAbout.setText("About");
            menuHelpAbout.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    helpAbout_ActionPerformed(ae);
                }
            });
            jCBoxCity1.setBounds(new Rectangle(225, 20, 110, 20));
            jLabel1.setText("Select your Home and First City:");
            jLabel1.setBounds(new Rectangle(25, 15, 160, 30));
            jLabel2.setText("Select your Second City:");
            jLabel2.setBounds(new Rectangle(60, 45, 135, 25));
            jCBoxCity2.setBounds(new Rectangle(225, 50, 110, 20));
            jLabel3.setText("Select your Third City:");
            jLabel3.setBounds(new Rectangle(70, 75, 125, 25));
            jCBoxCity3.setBounds(new Rectangle(225, 80, 110, 20));
            jLabel4.setText("Select your Fourth City:");
            jLabel4.setBounds(new Rectangle(60, 115, 120, 15));
            jCBoxCity4.setBounds(new Rectangle(225, 110, 110, 20));
            jButton1.setText("Quote");
            jButton1.setBounds(new Rectangle(80, 215, 75, 21));
            jButton1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    jButton1_actionPerformed(e);
                }
            });
            jButtonE.setText("Exit");
            jButtonE.setBounds(new Rectangle(270, 215, 75, 21));
            jButtonE.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    jButton2_actionPerformed(e);
                }
            });
            menuFile.add(menuFileExit);
            menuBar.add(menuFile);
            menuHelp.add(menuHelpAbout);
            menuBar.add(menuHelp);
            this.getContentPane().add(jButtonE, null);
            this.getContentPane().add(jButton1, null);
            this.getContentPane().add(jCBoxCity4, null);
            this.getContentPane().add(jLabel4, null);
            this.getContentPane().add(jCBoxCity3, null);
            this.getContentPane().add(jLabel3, null);
            this.getContentPane().add(jCBoxCity2, null);
            this.getContentPane().add(jLabel2, null);
            this.getContentPane().add(jLabel1, null);
            this.getContentPane().add(jCBoxCity1, null);
        }
    
        void fileExit_ActionPerformed(ActionEvent e) {
            System.exit(0);
        }
    
        void helpAbout_ActionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(this, new Main_AboutBoxPanel1(), "About", JOptionPane.PLAIN_MESSAGE);
        }
    
    
        private void jButton2_actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    
        private void jButton1_actionPerformed(ActionEvent e) {
            city1 = (String)jCBoxCity1.getSelectedItem();
            city2 = (String)jCBoxCity2.getSelectedItem();
            city3 = (String)jCBoxCity3.getSelectedItem();
            city4 = (String)jCBoxCity4.getSelectedItem();
            if (city1 == "Select One") {
                JOptionPane.showMessageDialog(this, "Please select the first City!");
            } else if (city2 == "Select One") {
                JOptionPane.showMessageDialog(this, "Please select the second City!");
            } else if (city3 == "Select One") {
                JOptionPane.showMessageDialog(this, "Please select the third City!");
            } else if (city4 == "Select One") {
                JOptionPane.showMessageDialog(this, "Please select the fourth City!");
            } else {
                if (city1 == city2) {
                    JOptionPane.showMessageDialog(this,
                                                  "A duplicated city has beed detected, Select another Second City!");
                } else if (city1 == city3) {
                    JOptionPane.showMessageDialog(this, "A duplicated city has beed detected, Select another Third City!");
                } else if (city1 == city4) {
                    JOptionPane.showMessageDialog(this,
                                                  "A duplicated city has beed detected, Select another Fourth City!");
                } else if (city2 == city3) {
                    JOptionPane.showMessageDialog(this, "A duplicated city has beed detected, Select another Third City!");
                } else if (city2 == city4) {
                    JOptionPane.showMessageDialog(this,
                                                  "A duplicated city has beed detected!, Select another Fourth City!");
                } else if (city3 == city4) {
                    JOptionPane.showMessageDialog(this,
                                                  "A duplicated city has beed detected!, Select another Fourth City!");
                }
            }
           
        }
       [COLOR="#FF0000"] void Miles_City12(int City1M2){
            
            if(city1=="Anaheim" && city2=="Arizona (Phoenix)" ){
              City1M2= 335;   
            }else if (city1=="Anaheim" && city2=="Atlanta"){
              City1M2 = 1918; [/COLOR]
            }
        }
    }
    How i can calculated the routes and the best route?
    Thanks

  2. #2
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default Re: Assignment

    1. First off!! I found errors in your code when I tried to run it.
    2. Second! Where is public static void main(String[] args)??? The program needs this to run and the code that you have provided cannot be run, so there is no use in me attempting to run this. When I added one, it still did not work. No GUI popped up and that was as far as I was going to go, to try to get your code to work.
    3. Remove the Color tags from the code tag. The [code] tags do all of the coloring itself.
    4. I suggest implementing ActionListener rather than do the method you are doing for ActionEvent. This will keep your code form becoming huge. With ActionListener implemented you can all of those button clicks in one nice little public void
    5. Using the name "Assignment" for your forum Thread makes people not want to answer reply to your forum. When people do this, we, the java-forum community, all assume you want a quick and easy answer that will fix all of your problems without ever doing any work for yourself. This is a place where a community of java programmers go to learn and understand new ways and approaches to programming in the [Java] Programming world. Not a homework hotline.
    6. Lastly, I cannot answer your last question:
      How i can calculated the routes and the best route?
      Because I have no idea how in depth this program needs to be. My idea, would be to have an array of values that tells you where the cities are in respect to a central point. The values will be the distance from the central point (make sure that the values of distance are absolute values, because you do not want negative numbers). Then include where the person lives and how long it would take to get form where they are to the place they want to be, in respect to the central point (think triangles!!!). Then, completely neglecting roads, traffic and geology, have the program find the fastest way get form one city to another (which would end up being a straight line). A for(;;) loop would work nicely, gather all of the variables in an array and find the one that has the least value. I am not sure if your assignment needs you to make an more accurate map, but this would at least be a start.

      I hope this helps. If this does work for you, do not ask me for the code needed to do this, try it out for yourself and give us the code you are working with and any errors/glitches that might have grown from it.
    awinston likes this.
    My API:
    Java Code:
    cat > a.out || cat > main.class

  3. #3
    neowolf is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default Re: Assignment

    The main class:
    Java Code:
    //
    // Oracle JDeveloper Stub Generated Source
    //
    package baseballapp;
    
    public class Baseball
    {
        //
        // Constructors
        //
        public Baseball() { }
    
        //
        // Methods
        //
        public static void main(java.lang.String[] p1) { }
    }

  4. #4
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: Assignment

    Quote Originally Posted by neowolf View Post
    The main class:
    Java Code:
    //
    // Oracle JDeveloper Stub Generated Source
    //
    package baseballapp;
    
    public class Baseball
    {
        //
        // Constructors
        //
        public Baseball() { }
    
        //
        // Methods
        //
        public static void main(java.lang.String[] p1) { }
    }
    First off, the java.lang.* package is automatically imported into every java class so can just type String[]. Second, the main method of your Baseball class doesn't actually do anything. The body is empty.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

Similar Threads

  1. Assignment help!!!!! PLEASE!
    By aznmanjj in forum New To Java
    Replies: 2
    Last Post: 11-21-2011, 12:08 AM
  2. HW assignment help
    By mackavelirip in forum New To Java
    Replies: 5
    Last Post: 03-31-2011, 03:34 AM
  3. Help with an assignment
    By aqeel2010 in forum New To Java
    Replies: 5
    Last Post: 01-14-2011, 09:04 AM
  4. assignment help
    By esallender in forum New To Java
    Replies: 4
    Last Post: 10-25-2010, 12:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •