# Thread: Finding the intercept using two equations.

1. Member Join Date
Dec 2009
Posts
3
Rep Power
0

## 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!  Reply With Quote

2. Moderator   Join Date
Feb 2009
Location
New Zealand
Posts
4,716
Rep Power
18

## 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.  Reply With Quote

#### Posting Permissions

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