Results 1 to 2 of 2
 12032009, 09:01 PM #1Member
 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 = ((xendxbeg)/2)+xbeg;
int ymiddle = ((yendxbeg)/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, xend50, yend+15);
g2.drawString(ylabel, xbeg40, ybeg+15);
g2.drawString(xlabel1, xmiddle5, yend+15);
g2.drawString(ylabel1, xbeg20, ymiddle+2);
g2.drawString(ldemand, xend25, yend30);
}
}
}
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!
 12032009, 09:32 PM #2Moderator
 Join Date
 Feb 2009
 Location
 New Zealand
 Posts
 4,585
 Rep Power
 12
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

Intercept key type
By carderne in forum New To JavaReplies: 3Last Post: 07232009, 03:57 PM 
Intercept CVS/SVN team commit
By dilipg003 in forum EclipseReplies: 2Last Post: 05122009, 07:17 PM 
Solving this equations problem in Java
By matt_well in forum New To JavaReplies: 17Last Post: 08302008, 10:05 PM 
[SOLVED] Algorithm for solving 2 equations, 2 unknowns
By Norm in forum Advanced JavaReplies: 0Last Post: 08242008, 05:27 PM 
equations
By Peter in forum New To JavaReplies: 2Last Post: 07042007, 07:15 AM
Bookmarks