How To Assign Numbers Obtain From Modular Equation To Certain Position In Array
Apr 16, 2015
My biggest issues are as follows:
1) I'm trying to use a logarithm to determine the length of a user input number. I keep getting an error stating <> indetifier expected. I'm assuming this means that the program is not recognizing the function of a logarithm. I know that normally you can include that information in the method, but my teacher has stated specifically that each of these methods be called something else, as shown in the code.
2) I'm not quite sure I understand how to assign the numbers I obtain from the modular equation to a certain position in the array. As I'm asking the user to input any number these values can change so therefore I can't simply state that first number = this place.Here is my code:
import javax.swing.*;
import javax.*;
public class getSize
{
public static void main( String[] args )
[code]...
View Replies
ADVERTISEMENT
Apr 14, 2015
I am learning about arrays in my class and my professor has a habit of throwing in code without explaining. We are doing a program called storing largest numbers where we read data from a file and place the larger of the two numbers in the corresponding position of a third array. They are in 4 by 4 format. Here is the ending code
import java.io.*;
import java.util.*;
public class prog464aStoringLargestNums
{
public static void main(String[] args)
[code]....
View Replies
View Related
Oct 2, 2014
package dicedemo;
public class DiceDemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
final int Die1_SIDES = 6; // Number of side of dice 1
final int Die2_SIDES = 6; // Number of side of dice 2
// Create two instances of the Die class.
[Code] ....
I need converting the number output to text: example one, two, three, etc.
View Replies
View Related
May 15, 2014
I am trying to assign random numbers to a deck of cards without repeating the numbers. What am I doing wrong?
package hokm;
import java.util.Random;
import java.util.Scanner;
public class Hokm
{
public static void main(String[] args) {
int [][] number=new int[52][2];
[Code] .....
View Replies
View Related
Jun 21, 2014
I have the following code in which I am looping through the rows of one array (composed of Strings) and copying it to another array. I am using .clone() to achieve this and it seems work as it changes the memory location of the rows themselves. I did notice that the String objects are still pointing to the same location in memory in both arrays but I won't worry about that for now, at the moment I just want to understand why the array I am cloning is not successfully assigning to the other array.
This is the incorrect line: ar[r] = maze[r].clone();
My code:
private String[][] maze = {{"*","*","*"," ","*","*","*","*","*","*"},
{"*"," ", "*"," "," "," ","*"," ","*","*"},
{"*"," ","*","*","*"," ","*"," ","*","*"},
{"*"," "," "," "," "," "," "," "," ","*"},
{"*","*","*","*","*"," ","*","*","*","*"},
{"*","*","*","*","*"," ","*","*","*","*"}};
//private String[][] mazeCopy = copyMaze(new String[6][10]);
private <T> T[][] copyMaze(T[][] ar){
for (int r = 0; r < ar.length; r++){
ar[r] = maze[r].clone();
}
return ar;
}
My compiler says: Required: T[]. Found: java.lang.String[]
Since ar[r] is an array and .clone() also returns an array why is this line incorrect.
View Replies
View Related
May 17, 2014
JButton btnNext = new JButton("Next");
btnNext.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
for (int i = 0; i < bkSorted.length; i++)
{
textArea.append("
" + bkSorted[i+1]);
}
}
});
When I click the button, it displays the whole array, instead of just the next array position. What am I doing wrong?
View Replies
View Related
Feb 7, 2015
I am trying to create an empty array that has no assigned length as the amount of elements it needs to hold will be dependent on another value. I then want to use a while loop to assign values to it. Here is an example of what im looking for it doesnt work. Iam trying to do:
int x = 12;
int i = 1;
int k = 0;
int[] factors = {}
while (i<x) {
if (x%i==0) {
factors[k] = i;
k++;
i++;
View Replies
View Related
May 5, 2015
I want to take my 5x5 array that reads data from a file, add the rows and columns, then print out a new 6x6 array with those values. Here is my code that shows I understand everything except this.
import java.io.*;
import java.util.*;
public class prog470cAddingRandC
{
public static void main (String [] args)
{
//read the file
Scanner inFile=null;
[Code] ....
I was told in a previous question to make the starting array 6x6 but that is not working. How do I take sum1 and sum2 and store that along with the values of the old array and print it?
View Replies
View Related
Feb 6, 2015
I have an assignment in which I have to design a method where I add an object at any given position in an array and shift the elements already in the array to make room. For example I have a collection class which holds trading card objects. So I wish to add a new trading card to this collection at a specified index or position with out deleting the current object already stored in the array . All this has to be done without the use of array lists, vectors or any abstract data types besides arrays . My question is how do I accomplish this . Say I wish to add a new trading card in position 4 the new card is added to my array and the card currently in position 4 gets moved to position 5 and the card in position 5 gets moved to 6 etc. The maximum amount of cards my collection can hold is 100. How would I add my trading card object to the specified position without overwriting what is currently there and shifting all other elements?Here is my current code.
public class CardCollection {
public BaseballCard [] collection;
final int MAX_CARDS = 100;
public CardCollection() {
collection = new BaseballCard[MAX_CARDS];
}
public CardCollection(BaseballCard[]c)
[code]...
position refers to the position in the CardCollection and not the position inside the array.
View Replies
View Related
Apr 3, 2015
I'm trying to build a monopoly like game, and atm I'm trying to find way how to build the Community and Chance chest cards. so far, my logic is
1-create an ArrayList of cards with a given order
2-for a given number of times(for loop) generate 2 random numbers ,which will be the parameters for Collection.swap().
3-swap.
here's the code for the shuffler Button
shuffler.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for(int i=0;i<shuffeledMessages.length;i++){
int randoma=(int)(Math.random()*4);
int randomb=(int)(Math.random()*4);
Collections.swap(myMessages,randoma,randomb);
}
}
});
For now things seem to work pretty ok, but I'm wondering if this is a good and efficient way to shuffle a card chest especially in case of large number of cards. plus, I'm not sure what would be a good loop count for effective shuffling, in my case I used i<arraylist.size
View Replies
View Related
Apr 16, 2014
Started learning about Array's I'm doing an exercise where you create a for loop that randomly assigns values to each element within the array, but where is my code going wrong?
import java.util.Scanner;
public class ArrayExamples{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double exampleArray[] = new double[5];
System.out.print("Enter a Number: ");
int num1 = input.nextInt();
[Code] .....
View Replies
View Related
Dec 16, 2014
I am writing a program for a game. It is between the user and a virtual player. The game starts with a pool of consecutive integers 1-100. The size of the pool is based on a random generated number at the beginning of the game. At the start, both players' scores are 0. For each turn, the player picks one number from the pool. That value is added to the player's score, the computer gets the sum of all the remaining numbers in the pool that divide evenly into the player's pick. The player's pick and its divisors are then removed from the pool.
The player should be able to play the game as many times as she wants without ending the program. Instructions should appear on the screen only once at the start of the program.
For each turn, both players' current score, the current pool of numbers, and a prompt for a number to be entered should show onscreen. I have written the code until I get to the function that updates the pool of numbers after a turn.
import java.util.Scanner;
import java.util.Random;
public class SlickPick {
public static void main (String[] args){
Scanner read = new Scanner(System.in);
int []pool = new int[100];
[Code] ....
My thinking is that I need to use the binary search to find the indexes of the divisors array and then use those indexes as the start values. I'm not sure how to assign the divisors indexes to start. Do I need an array for start? Whenever I run the program, the only value missing is 3.
//Name : poolUpdate
//Description : This function modifies the contents of the pool as a result of a turn of play.
//Parameters : The pool array, the divisors array, the size, and the user's pick.
// :
//Return :
public static void poolUpdate(int[] pool, int[] divisors, int size, int pick){
int low=0;
int high=size-1;
[Code] ....
View Replies
View Related
Apr 24, 2014
I've just written a program that generates 100 numbers that range from 0 ~ 25 using arrays, the program calls another method that sorts the even numbers into a separate array and returns the array. I need it to display both arrays, however, when I run my program, the numbers of both arrays are mixed together, and I'm not sure how to separate them.
[ public class Array1
{
public static void main(String[] args)
{
int array [ ] = new int[100];
for (int i = 0; i < array.length; i++)
{
array[i] = (int) (Math.random() * 26);
[Code] .....
View Replies
View Related
Mar 19, 2014
i have created a table in jsp, i want to obtain the contents of a td at the servlet.For example, here's one td of table:
<td align="center" title="tdun" id="cat"> <%= categoryname %> </td>
I want to get this value in my servlet .
View Replies
View Related
Oct 10, 2014
I'm doing this project where I need to make a persian carpet using recursive methods. I already have my recursive what I'm trying to implement is the use of color. My method BorderColor draws a square using a random color choose from an array.
public void Cuadrado(Graphics g){
Random color = new Random();
g.setColor(colors[color.nextInt(colors.length)]);
g.drawLine(left, top, right, top);
g.drawLine(left, top, left, bottom);
[Code] ....
What I'm trying to do is getting the color from 4 different corners in order to create a new one and make a recursive call. I already tried using the method getPixelColor from the Robot() object but I quit it because is a recursive method and it may cause trouble with the recursive stack. I created this method to create the new color and then call it in the PersianRug method, but I dont have a clue on how to obtain and implement the new colors.
public int newColor(int c,int c1,int c2,int c3, int a){
int c4=((c+c1+c2+c3)%13)*a;
return c4;
}
View Replies
View Related
Jan 11, 2014
I've found following code for Singleton Implementation from this forum, I am having a difficulty of understanding following,
1. When Singleton instance will be created, ( From which call ) ?
2. What feature of Static Inner class allow object to be singleton ?
3. How Inner Class implementation is thread safe ?
4. What will happen if variable "instance" mark as non-static, Will it still grantee singleton implementation ?
Java Code:
public class Singleton {
// Note private constructor
private Singleton() {}
private static class SingletonInner {
private final static Singleton instance = new Singleton();
}
public static Singleton getInstance() {
return SingletonInner.instance;
}
} mh_sh_highlight_all('java');
View Replies
View Related
Oct 4, 2014
I use jboss eap 6.2 under eclipse.I perform a tutorial on EJB and I want to show the difference between a stateless session bean and a statefull session bean. I want demonstrate that the first one keep its state (if it has one) but that 2 successive don't send back necessarily the same SLSB : it send back the SLSB that is ready in the pool. But I don't suceed in obtaining 2 different SLSB by 2 successive call. The system always send me back the same SLSB.
View Replies
View Related
Jun 19, 2014
a new java executable file which does heavy processing (batch). Development hasn't really started yet and the design phase is just beginning. Now the client is asking us to give them the minimum server specs to be able to run our application..I'm thinking this can't be done without performance testing, which will be after development. Is there a better and faster way to be able to assess this?
View Replies
View Related
Oct 24, 2014
Part 1: USING A WHILE OR A DO-WHILE LOOP write a program to compute PI using the following equation:
PI = 3 + 4/(2*3*4) - 4/(4*5*6) + 4/(6*7*8) - 4/(8*9*10) + ...
Allow the user to specify the number of terms (5 terms are shown) to use in the computation. Each time around the loop only one extra term should be added to the estimate for PI.
Alter your solution from part one so that the user is allowed to specify the precision required between 1 and 8 digits (i.e. the number of digits which are correct; e.g. to 5 digits PI is 3.14159), rather than the number of terms. The condition on the loop should be altered so that it continues until the required precision is obtained. Note that you need only submit this second version of the program (assuming you have it working).
My output for part 1 is :
Enter number of wanted terms for value of PI
100
PI = 3.1666666666666665 Number of Term = 2
PI = 3.1333333333333333 Number of Term = 3
PI = 3.145238095238095 Number of Term = 4
PI = 3.1396825396825396 Number of Term = 5
PI = 3.1427128427128426 Number of Term = 6
PI = 3.1408813408813407 Number of Term = 7
PI = 3.142071817071817 Number of Term = 8
PI = 3.1412548236077646 Number of Term = 9
PI = 3.141839618929402 Number of Term = 10 ................ and so on
I know you have to compare value of current Pi to the previous one but I'm stuck.
View Replies
View Related
Jan 29, 2015
This first part of code is my HTML
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta charset="UTF-8">
<link href="jquery/jquery.mobile-1.4.5.min.css" rel="stylesheet" type="text/css"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
[Code] .....
View Replies
View Related
Jan 21, 2015
I am writing a program for finding the profit made after paying the broker. here is my code, I am wondering why Java
Code: paidBroker = commission + commissionAfterSale; mh_sh_highlight_all('java');
is being added to
Java Code: noProfit = profit - paidBroker; mh_sh_highlight_all('java');
Here is my full program, you can find these lines of code on lines 64 and 70.
Java Code:
import java.util.Scanner;
public class StockTransaction {
public static void main(String[] args) {
// TODO Auto-generated method stub
//Variable Declaration Section
[Code] ....
View Replies
View Related
Sep 19, 2014
So Ive got to make a turtle on an image draw a semicircle that starts at the top of a circle and goes down and to the left, changing colors halfway through. I've got everything down, I can draw the turtles and make them do straight lines. My problem is more math related. I need to use the equation of a circle, give it points, and figure out how to write that code in java.
We use the equation for a circle: (x - a)^2 + (y - b)^2 = r^2
amanda.setName("amanda");
amanda.setShellColor(Color.BLUE);
amanda.setBodyColor(Color.RED);
amanda.setPenColor(Color.YELLOW);
amanda.setPenWidth(3);
amanda.forward();
amanda.turn(-90);
amanda.setPenColor(Color.BLUE);
amanda.forward(???);
the question marks are where I need to draw a line on an arc, like in the picture.
View Replies
View Related
Apr 26, 2014
I want make a math equation game. usually math game use equation for the question and we answer that equation. ex : what is the result of 2*5 / 2+2/ 2^2 etc. and we answering that. but i want to make it different so i want to make the equation answer as the question and the equation as the answer of the game. Ex : the question is 54 so we can answer it with 9*6 or 24+30. and this is my java code
package coba;
import java.util.Scanner;
public class Coba {
public static void main(String[] args) {
double angka = Math.random()*70;
[Code] ....
but when i run it the error code show like this : Quote
View Replies
View Related
Mar 15, 2015
The question states: 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.
Write a test program that prompts the user to enter a, b, c, d, e, and f and displays the result. If ad − bc is 0, report that "The equation has no solution."
I believe that my program is correct because I am able to compile it and get no errors, however I have no clue how to display the information for x and y or display this equation has no solution if ad-bc=0.
Java Code:
import java.util.Scanner;
public class Exer911 {
public static void main(String[] args){
// Create a scanner system to hold the numbers for each variable
Scanner input = new Scanner(System.in);
// Prompt the user to enter a number for each of the variables
[Code] ....
How to get the information to display ....
View Replies
View Related
Oct 14, 2014
I just created a program to calculate the roots for a 2. degree equation, When I first created my program, I defined the r1 and r2 as double, but got an error saying they needed to be defined as String, why is that?When should I be using string? I am new to java and I have mostly only used int, double and Boolean so far.
import java.util.Scanner;
import java.text.DecimalFormat;
public class c3e1 {
public static void main(String[]args){
[code]....
View Replies
View Related
Jan 27, 2014
I am running into some trouble with Line-Plane intersection, my method works, provided I am perpendicular to the plane I want to intersect. This is caused be the plane equation (with my given x, y, and z coordinates, the equation is -Z - 1 = 0). So the equation is only relying on the Z value of anything inputted. Is there another way to calculate the equation of a plane that would rely on all axis? Here is my current code:
Java Code:
Vector3f A = new Vector3f(0, 0, -1);
Vector3f B = new Vector3f(0, 1, -1);
Vector3f C = new Vector3f(1, 1, -1);
Vector3f v1 = new Vector3f(B.x - A.x, B.y - A.y, B.z - A.z);
Vector3f v2 = new Vector3f(C.x - A.x, C.y - A.y, C.z - A.z);
float[] i = new float[]{v1.x, v2.x};
float[] j = new float[]{v1.y, v2.y};
float[] k = new float[]{v1.z, v2.z};
[Code] ....
View Replies
View Related