Results 1 to 2 of 2
  1. #1
    MapleLeafRag is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default Finding the intercept using two equations.

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.applet.*;
    import java.text.*; // For formatting numbers
    import javax.swing.*;
    import javax.swing.JOptionPane;
    import javax.swing.JApplet;
    import java.awt.Graphics;

    public class Finals extends JApplet{

    double input;
    double equilibriumprice;
    double equlibriumquantity;

    public void init(){

    String firstNumber;
    String secondNumber;
    String thirdNumber;
    String fourthNumber;
    String fifthNumber;
    String sixthNumber;
    String seventhNumber;
    String eighthNumber;
    String ninthNumber;

    double number1;
    double number2;
    double number3;
    double number4;
    double number5;
    double number6;
    double number7;
    double number8;
    double number9;

    firstNumber = JOptionPane.showInputDialog("What is the value of the price floor");
    secondNumber = JOptionPane.showInputDialog("We now need two points on the demand schedule, what is the price of the first point?");
    thirdNumber = JOptionPane.showInputDialog("What is the corresponding quantity?");
    fourthNumber = JOptionPane.showInputDialog("What is the price of the second point?");
    fifthNumber = JOptionPane.showInputDialog("What is the corresponding price?");
    sixthNumber = JOptionPane.showInputDialog("We now need two points on the supply schedule, what is the price of the first point?");
    seventhNumber = JOptionPane.showInputDialog("What is the corresponding quantity?");
    eighthNumber = JOptionPane.showInputDialog("What is the price of the second point?");
    ninthNumber = JOptionPane.showInputDialog("What is the corresponding quanity?");

    number1 = Double.parseDouble(firstNumber);
    number2 = Double.parseDouble(secondNumber);
    number3 = Double.parseDouble(thirdNumber);
    number4 = Double.parseDouble(fourthNumber);
    number5 = Double.parseDouble(fifthNumber);
    number6 = Double.parseDouble(sixthNumber);
    number7 = Double.parseDouble(seventhNumber);
    number8 = Double.parseDouble(eighthNumber);
    number9 = number1 = Double.parseDouble(firstNumber);
    number2 = Double.parseDouble(secondNumber);
    number3 = Double.parseDouble(thirdNumber);
    number4 = Double.parseDouble(fourthNumber);

    input = number1;
    }


    public void paint(Graphics g){

    super.paint(g);

    g.drawRect(15, 10, 270, 20);

    g.drawString("The price floor is " + input, 25, 25);

    String xlabel = "Quantity";
    String ylabel = "Price";
    String xlabel1 = "Q*";
    String ylabel1 = "P*";
    String ldemand = "D*";
    Font font;
    int xbeg = 50;
    int ybeg = 50;
    int xend = 350;
    int yend = 350;
    int xmiddle = ((xend-xbeg)/2)+xbeg;
    int ymiddle = ((yend-xbeg)/2)+ybeg;

    BasicStroke stroke = new BasicStroke(2.0f);
    BasicStroke wide = new BasicStroke(4.0f);

    float dash1[] = {6.0f};

    BasicStroke dashed = new BasicStroke(2.0f,
    BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
    2.0f, dash1, 3.0f);

    {
    font = new Font("Helvetica", Font.BOLD, 14);
    }


    {
    Graphics2D g2 = (Graphics2D) g;
    g2.setColor(Color.black);

    g2.setStroke(wide);
    g2.draw(new Line2D.Double(xbeg, yend , xend, yend));
    g2.draw(new Line2D.Double(xbeg, ybeg , xbeg, yend));

    //Demand
    g2.setStroke(stroke);
    g2.setColor(Color.green);
    g2.draw(new Line2D.Double(xbeg + 20, ybeg + 20, xend - 20, yend - 20));

    //Supply
    g2.setStroke(stroke);
    g2.setColor(Color.red);
    g2.draw(new Line2D.Double (xbeg + 20, yend - 20, xend - 20, ybeg +20 ));

    g2.setStroke(dashed);
    g2.setColor(Color.red);
    g2.draw(new Line2D.Double(xbeg, ymiddle, xmiddle, ymiddle));
    g2.draw(new Line2D.Double(xmiddle, yend, xmiddle, ymiddle));

    g2.setColor(Color.black);
    g2.setFont(font);
    g2.drawString(xlabel, xend-50, yend+15);
    g2.drawString(ylabel, xbeg-40, ybeg+15);
    g2.drawString(xlabel1, xmiddle-5, yend+15);
    g2.drawString(ylabel1, xbeg-20, ymiddle+2);
    g2.drawString(ldemand, xend-25, yend-30);


    }

    }
    }


    So the difficulty I'm having is defining what the double equlibriumprice would be set to. Basically, I can find the slope of two lines using the input the users gives me. Than I can find B for the classic y=mx+b. But than, I need equilibrium price to be mx+b(demand)=mx+b(supply). But I'm not quite sure how you would get Java to solve for an unknown variable. Any help would be appreciated!

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    That's a lot of code. But is it a Java question? From a brief read of the code, you obtain four points from the user and want to calculate the intersection of line segments joining those points in pairs. If so you need some algebra: google "equation of line given two points" and "intersection of two lines". It's tedious, but straight forward, algebra.

Similar Threads

  1. Intercept key type
    By carderne in forum New To Java
    Replies: 3
    Last Post: 07-23-2009, 02:57 PM
  2. Intercept CVS/SVN team commit
    By dilipg003 in forum Eclipse
    Replies: 2
    Last Post: 05-12-2009, 06:17 PM
  3. Solving this equations problem in Java
    By matt_well in forum New To Java
    Replies: 17
    Last Post: 08-30-2008, 09:05 PM
  4. Replies: 0
    Last Post: 08-24-2008, 04:27 PM
  5. equations
    By Peter in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 06:15 AM

Posting Permissions

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