00:01
In this video, we will create a program that solves two by two linear equations.
00:04
A linear equation can be solved using kramer's rule, which is shown on the right hand side of the screen.
00:08
The program will prompt the user to enter six numbers and display the result.
00:11
However, if a times d minus b times c equals zero, then the equation has no solution.
00:16
This is because our calculated x and y values on the right hand side of the screen have a times d minus b times c as denominators.
00:25
So we cannot divide by zero.
00:28
This is why.
00:30
I've declared our class as well as the main method within it.
00:33
I've also imported java .util .scanner, since we know we'll be taking user input.
00:38
So the first thing we can do is go ahead into our main method and create a new scanner object.
00:51
Named input by calling scanner with the argument system .in, which allows keyboard input to be read from inside the java application.
00:59
Scanner input equals new.
01:03
Scanner again we're using argument system .m.
01:09
Now we'll want to prompt the user to enter values a through f and save each using the next double method of java util scanner class.
01:19
This just scans the next token of the input as a double.
01:23
So we use system .out .println to prompt the user to phase enter a value for a.
01:40
I will save r2a as input.
01:46
The next double.
01:51
Now i'm just going to copy and paste since we'll be doing the same thing for b, c, d, and e.
02:29
And lastly, f at this point, we'll have prompted the user to enter values as well as save them.
02:40
So now we can calculate a times d minus b times c.
02:46
So we can just do this within the if statement, since we'll need to check whether or not this value equals zero.
02:53
So we'll start with an if statement.
02:56
When we calculate a times d minus b times c, this is going to give us a double, but we want to check to see if this is zero, essentially.
03:13
The way we can round this is just to cast our calculation as an in before checking for equality with zero.
03:29
So in the event, it is zero.
03:34
We can use system that out.
03:36
That is an plan.
03:38
And let the user know the solution or rather the equation has.
03:46
No solution.
03:51
And then we're going to let them know why...