I am suppose to write a method for solving a quadratic equation using the following header:
public static int solveQuadratic(double[] eqn, double[] roots)
I have entered 1, -3 and -4. The answer I get is "The solution is:0.0" .
import java.util.Scanner;
public class QuadratilEq {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner (System.in);
double[] eqn = new double[3];
double[] roots = new double[4];
I am working on and am stuck on an assignment where we draw and then solve a Kakuro game.we have been given DrawingPanel.java and DrawGrid.java which should draw the board game grid then we need to pass a .txt document which has the game information
I tried getting my readGrid function to read the input file and store it in arrays but it is not working?
//main -get arguments -make grid -solve it import java.io.File; import java.util.Scanner; import java.util.Arrays; public class Kakuro { static File gridFile; // The input file describing the grid
This was the way I was supposed to write it (every thing separated). Any way, I was wondering why when ever I try to run I only get NaN for roots, and my discriminant is off
/** * Find roots of quadratic equations */ import java.util.Scanner; public class QuadraticProject { public static void main(String[] args) {
I have just started to learn programming in the book I am teaching myself from it said how would you write the following arithmetic expression with it being the quadratic formula but only the plus part of it in the plus or minus..
package javalearning; import java.util.Scanner; public class QuadraticFormula { public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.print("Enter value for B: "); double B = input.nextDouble(); System.out.print("Enter value for A: "); double A = input.nextDouble(); System.out.print("Enter value for C: "); double C = input.nextDouble(); double negativeOfB = -B;
Write a program named QuadraticTable.java that takes three double arguments and two int arguments (in that order) from the command line. The three doubles will represent a, b, and c from the quadratic formula.
If the discriminant is non-negative, find and print the solutions to the quadratic equation. (The plus/minus sign in the quadratic formula indicates that you would separately perform both operations). Otherwise print "no real solutions".
Then using the last two int arguments as x_min and x_max, print a table of x and ax
2 + bx + c
values using the a, b, and c read in as command line arguments.
Sample output: (command line arguments were 1 0 2 -3 3)
I have been working on a program that takes in a 2d array (there is a method to convert to 1d as necessary) and uses it as an 8 puzzle, which the program then solves (if it is solvable) using the A* Search algorithm, outputting each solution move. It needs error checkers/traps/exception handlers, and be able to create an 8 puzzle from user input, create an 8 puzzle from file input, and create an 8 puzzle from file input and then output to another file the solution move sequence. I have gotten nearly everything done except for implement the algorithm itself and the methods for handling input from files or output to files (the input/output file methods are a minor problem that I can probably solve fairly easily, I just want to be able to test the a* with the puzzle created from user input first.
I have taken several cracks at it, but I am not really good with Java in this type of situation and this is hurting me a lot. I have put in a method to determine if a puzzle is solvable, but the A* algorithm still eludes me. I understand the concept of the algorithm, you have a heuristic function, a cost function (each move equals 1 in this case), and you add the two together to get f(n), choosing the move that will get you the closest to your goal (best first search basically). here is what I have so far that works:
import java.io.File; import java.io.IOException; import java.util.Queue; import java.util.Scanner; public class Puzzle { public static void main(String[] args) throws IOException {
[Code] ....
I have it outputting things to make sure all that works already, I have all the error handlers, but I think that before I can even implement the A*search algorithm, there may be something else I need. Conceptually, I understand I need Nodes, States and Stacks, and Queues (I think, I am not sure about this), but with the way my code has been made so far, I am not sure how to implement those and then implement them with the A* algorithm. What I should do next? I have looked at the code of other uses of A* algorithm(that is how I found out I might need Java data structures like queue and stack and list), but I am not sure exactly where to go to from where I am.
Design a class named LinearEquation for a 2 X 2 system of linear equations:
ax + by = e cx + dy = f Where x = ed − bf/ad − bc y = af − ec/ad − bc
The class contains:
- Private data fields a, b, c, d, e, and f. - A constructor with the arguments for a, b, c, d, e, and f. - Six get methods for a, b, c, d, e, and f. - A method named isSolvable() that returns true if ad−bc is not 0. - Methods getX() and getY() that return the solution for the equation.
[code].....
how to display the information I need to display. Also I am not so sure that I wrote the code properly, I do not get any errors when I compile it.
I am in search of a library that has been created in JAVA that can be utilized to solve for roots of a nonlinear system of equations. Each equation has 2 variables, x and y, and will need a library that uses higher calculus equations. No ones that just solve for x.
Most of the libraries that have been created to solve nonlinear equations are either in Fortran, C, or Python. There are a few libraries such minpack/scipy. The only libraries that I have been able to find or programming solutions that are in JAVA either require additional programs such as Matlab or are commercial products
I did find one library put together by a professor in Colorado State, but am unsure how to use it. There does not seem to be a way to enter your functions in the code.
Newton Raphson Method - Multivariable(x and y)
[URL] .....
How to use this library or find a library that can be used in an android application would be amazing.
So i was assigned to write a program that would print the answer to the system of two linear equation. the form of ax+by=c and dx+ey=f..I wrote this program, but it is incorrect since I tried it out on my terminal and I keep getting incorrect values.
import java.util.Scanner; public class Quest4 { public static void main(String[] args) { Scanner input = new Scanner(System.in);
I am in search of a library that has been created in JAVA that can be utilized to solve for roots of a nonlinear system of equations. Each equation has 2 variables, x and y, and will need a library that uses higher calculus equations. No ones that just solve for x.
Most of the libraries that have been created to solve nonlinear equations are either in Fortran, C, or Python. There are a few libraries such minpack/scipy. The only libraries that I have been able to find or programming solutions that are in JAVA either require additional programs such as Matlab or are commercial products
I did find one library, but am unsure how to use it. There does not seem to be a way to enter your functions in the code.
Newton Raphson Method - Multivariable(x and y) www(.)math.colostate(.edu)/~benoi...s/solvers.html
How to use this library or find a library that can be used in an android application.
I have a .txt file which i am currently using Scanner to input into the console, the text file contains the names of football games followed by their scores:
E.g. Man U : Liverpool : 2 : 1
I need to create an equation to add together all scores to create a string reading something like "total goals: 28" ....
So I need to create a square and make it rotate when the letter R is pressed and then make it stop when the letter R is pressed again. I need make it rotate using a maths equation that I can't figure it out myself right this moment.
Code for square:
package lab2; public class Square { public double [][] vertices = new double[4][2]; //not good to make this public public Square(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { vertices[0][0]=x1; vertices[0][1]=y1; vertices[1][0]=x2;
[Code] ....
In the Square code there is a method to write an equation to rotate it but I can't figure that part out ....
I am in search of a library that has been created in JAVA that can be utilized to solve for roots of a nonlinear system of equations. Each equation has 2 variables, x and y, and will need a library that uses higher calculus equations. No ones that just solve for x.
Most of the libraries that have been created to solve nonlinear equations are either in Fortran, C, or Python. There are a few libraries such minpack/scipy. The only libraries that I have been able to find or programming solutions that are in JAVA either require additional programs such as Matlab or are commercial products
I did find one library put together by a professor in Colorado State, but am unsure how to use it. There does not seem to be a way to enter your functions in the code.
Newton Raphson Method - Multivariable(x and y) Page Not Found
How to use this library or find a library that can be used in an android application would be amazing.
There are a lot of variables in physics and it is easy to manipulate equations to find the unknown variable. Well, in my program I have the problem of determining which equation to solve for an unknown. You can see I have a timeF, timeI, time, distanceI, distanceF, distance...etc...variables. The way that I have written the code, it will scan for an empty() JTF and assign it as the unknown variable (not sure I can do it this way anymore). At that point, the value is passed into the correct calculation method to process the equation based on a series of case statements in each method...
I know the button arrays I have set up will process correctly in the checkJTF method...and I will need to account for that...but right now my focus is on getting the program to properly calculate the kinematics equations and display the result in the JPanel.
public class PhysicsFrame extends JFrame { //Kinematic variables private static float distanceI, distanceF, velocityI, velocityF, velocityAverage, acceleration, time, timeF, timeI, result; //Power variables
I mainly would like to know is a int[4][4] or a int [4*4] is more efficient to use. Which takes more storage? Which requires more to process? that kind of stuff.
I'm wonder about the issue of constructor for arrays. Let say I have a class tablica, and one component int[] tab. If I get it right until now tab is nothing more than empty reference to some unexisting array?
import java.util.Random; class tablica{ int[] tab; tablica (){ // i wish it was constructor
[code]....
Then, I'm trying to build the constructor for class tablica. What can be the parameter of such constructor? Is it fields of array? It is simple forf for basic variable
- I liken values defined in constructor with those global defined in class. But how to do it with array component tab.
If I create array object in main method then how can I use this constructor?
In the program below I populated three arrays: student id, name, and GPA. The findStudent() method attempts to match users input with the input stored in the studentID array using an if/ else statement. When I use the if/ else statement the else always executes regardless if the IDs match? I am trying to get JOptionPane.showMessageDialog(null, "Incorrect entry"); to print only if the IDs don't match.
Java Code:
//FILE: StudentIDArray.java import javax.swing.*; //Used for the JOption dialog boxes import java.util.*; //Used for Scanner input public class StudentIDArray { boolean nameFound = true; final int numOfElements = 2; //Final int to control to loop for data
I'm working on a side project, which will eventually hopefully be a Pokedex, and I've just been going to it at the end of every chapter and using the stuff I've learned to work on it.So I just read chapter 3, which is all about variables and teaches how to use arrays.
my question is, does an array have to be declared inside a method? Because I'm trying to create an array inside a class without any methods and without the main, and I continuously get errors. Here's a quick working of my code that won't compile.
class blah { blah a[] = new blah[7]; a[0] = new blah(); }
The error message focuses on a[0] = new blah(); Telling me the 0 should be a ], the = is an illegal start of type, so on and so forth. The program compiles completely fine if it's within a method, like this:
class blah { void a() { blah a[] = new blah[7]; a[0] = new blah();
}
}
Or if I have public static void main (String[]args); But I'm trying to practice working outside of main.So does an array have to be within a method,
I have created a class and a matrix of doubles (or at least, I think I have, that's partly what I want to verify).I need to return the values of the array,Here is my class:
public class example{ double[][] Position=new double[2][11]; double calculate(){ for (int time=0;time<=10;time=time+1){ Position[1][time]=time; Position[2][time]=time+1; double A=Position[2][time]; return A; } } }
I am getting the error: "This method must return a result of type double", though to me it looks like I am returning double (A).
I am having trouble conceptualizing how to fill arrays. I understand that I can declare one and number it's elements, and it stores values of a certain data types. I don't really understand beyond that. Like how I would fill and use data in it.
I can be more specific with an assignment I have for school, but need to get started understanding how to fill arrays with data and then how to use that data.
So im making this ghost game where i display an 8x8 filled with 0s and a randomly generator five 1s in there I can get it to display 0s and add 1s, however sometimes the 1s that are randomly generated sometimes go on the same spot making it look like there are only four 1s. How would i go about fixing that?
package Grade12; import java.util.Random; public class Ghost { public static void main(String[] args) { Random generator = new Random(); int gameboard [][] = new int [8][8]; int randomx, randomy, counter = 0, sum = 0; for(int row = 0; row < 8; row++){ for(int col = 0; col < 8; col++){ (gameboard[row][col]) = 0; }
hours - An array of seven integers to hold the number of hours worked by each employee.payRate - An array of seven doubles to hold each employee's hourly pay rate.wages - An array of seven doubles to hold each employee's gross wages.The class should relate the data in each array through the subscripts.
For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose identification number is stored in element 0 of the employeeID array. That same employee's pay rate should be stored in element 0 of the payRate array. In addition to the appropriate accessor and mutator methods, the class should have a method that accepts an employee's identification number as an argument and returns the gross pay for that employee.Demonstrate the class in a complete program that displays each employee number and asks the user to enter that employee's hours and pay rate. It should then display each employee's identification number and gross wages.Input Validation: Do not accept negative values for hours or numbers less than 6.0 for a pay rate.
My problem with this program is that everytime I try to print the employee ID's or the wages, I get hashcode or something like it (#[I1a77cdc or something like that). I tried using the toString method, but it lists all of the values, when I'm trying to display one at a time. Here is the code for the class:
// moduleArray class public class moduleArray { final int NUM_EMPLOYEES = 7; int[] employeeID = {5658845, 4520125, 7895122, 8777541, 8451277, 1302850, 7580489}; int[] hours = new int[NUM_EMPLOYEES];
[code]...
This is the demo program to list the ID's. I've been messing with it for some time, and right now I just want it to display values.
import java.util.Scanner; public class moduleArrayDemo { public static void main(String[] args) { final int NUM_EMPLOYEES = 7; int[] ID = new int[NUM_EMPLOYEES];
Okay, so the assignment was creating a word search for the given array. I've created all the code necessary, but I've ran into trouble. This problem occurs with the Up-Forward, Up-Backward, Down-Forward, and Down-Backward sections. If I only set one of these to run, it works. But if I have all 4 set at the same time, it errors out on the first one that runs.
public class P_WordSearch { public static void main(String[] args) { char[][] puzzle = { {'B','O','O','G','S','R','O','W','I','N','G'}, {'E','B','L','G','N','I','M','M','I','W','S'}, {'L','C','E','A','T','I','P','U','P','I','S'}, {'C','M','I','N','C','A','X','Y','O','S','N'},
I am trying to concatenate two arrays but on on compiling it is showing
Java Code: import static java.util.Arrays.*; class Mergesort { public static void main(String...s) { Mergesort r=new Mergesort(); int x[]={1,2,3,4,5,6}; int y[]={9,8,7,15,14,13,12,11};