Write A Method Which Initializes A 2D Target Array
Apr 11, 2014
So here is a method i wrote for the first part for initializing an array:The question was, "write a method which initializes a 2D target array (assuming all other classes have been imported and given), and all targets should be stationary."and this was my method i wrote:
public void initializeTargetArray(Target[][] targets) {
int row = targets.length();
int col = targets[0].length;
for(int i = 0; i < row; i++)
for (int j = 0; j < col; j++)
targets[i][j] = new Target(Target.STATIONARY, false);
}
Now my question how do I initialize an array similar to the method above for a different question?
Quote
Part b
Write a method which initializes an array (You can assume that the 2D array itself (but not the Target
objects inside) is already initialized), where the game level stage is now set:
Game level 1 - all targets are stationary,
Game level 2 - For even numbered rows, targets at even numbered columns are stationary, targets at odd
numbered columns are movable. For odd numbered rows, targets at odd numbered columns are
stationary, targets at even numbered columns are movable.
Game Level 3 - All targets are movable.
public void initializeTargetArray(Target[][] targets, int gameLevel) {
//*** Finish this method. ***//
View Replies
ADVERTISEMENT
Apr 22, 2014
i have to "Write a method called addToOverThirty which takes the array nums3 as a parameter. It adds 1 to all numbers that have a value greater than 30 in the array.
Add a call to the addToOverThirty method, then display a message telling what the output is followed by the results For example:The nums3 array after adding 1 to all numbers greater than 30 is10 6 15 and so on (check with the values you assigned to nums3)"its pointless because we were told not to make the array have a number over 30.
import java.lang.*;
import java.util.*;
public class LastProject
public static void main(String[] args) {
int nums1[] = new int[15];
int nums2[] = new int[15];
int nums3[] = {5,2,15,8,26,22,1,29,4,23,30,11,19,6,24};
[code]....
View Replies
View Related
Dec 8, 2014
How to copy the target of a link? I am using Apache's FileUtils class. I have tried the following and it only copies the link, not the target:
import org.apache.commons.io.FileUtils;
import java.io.File;
public class Copier {
public static void main(String[] args) {
File sourceFile = new File("C:/Demo/sourceDir/a_link.lnk");
File destinationDirectory = new File("C:/Demo/destinationDirectory");
FileUtils.copyFileToDirectory(sourceFile, destinationDirectory);
}
}
View Replies
View Related
Apr 11, 2014
I've created a constructor in bean and put an value to my string after doing so all started to work properly. I am trying to get my application to work but no luck so far. I have looked for similar issues but although there were similar I've got no luck in fixing mine.
When I am trying to put an value in the input file i got error message (/zadanie_1.xhtml @15,75 value="#{z_1.lancuch}": Target Unreachable, identifier 'z_1' resolved to null).
My starting page:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
[Code]......
View Replies
View Related
Jan 7, 2015
I am trying to implement the JSF 2.0 project with Primefaces from one of the tutorial, i con login with only jsf but not when i use primeface where i am getting following error.
Error Log
HTTP Status 500 - /login2.xhtml @23,98 value="#{employee.userName}": Target Unreachable, identifier 'employee' resolved to null type Exception report
message /login2.xhtml @23,98 value="#{employee.userName}": Target Unreachable, identifier 'employee' resolved to null description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: /login2.xhtml @23,98 value="#{employee.userName}": Target Unreachable, identifier 'employee' resolved to null
javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)root cause
[Code] ....
Note The full stack trace of the root cause is available in the Apache Tomcat/7.0.57 logs. in Apache Tomcat/7.0.57
Employee.java
package com.login.sample;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.annotation.PostConstruct;
[Code] ....
I am trying to create a login page with a database in which i am getting this error. I am not getting this bean properties.
View Replies
View Related
Jun 5, 2014
I was reading the oracle java tutorial under: URL....Here's the code for the Point class:
public class Point {
public int x = 0;
public int y = 0;
//constructor
public Point(int a, int b) {
x = a;
y = b;
}
}
and in the Rectangle class you have the following constructor:
public Rectangle(Point p, int w, int h) {
origin = p;
width = w;
height = h;
If we create a new Point object like this:
Point originOne = new Point(23, 94);
and then a new Rectangle object like this:
Rectangle rectOne = new Rectangle(originOne, 100, 200);
Will that set originOne to point to the object Point at (23, 94). just want to make that this is the meaning of this statement: Point(Point p)Constructs and initializes a point with the same location as the specified Point object.
View Replies
View Related
Jun 7, 2014
JFrame parentFrame = new JFrame();
File f12=new File("E:
ewfile.txt");
JFileChooser fileChooser = new JFileChooser();
fileChooser.setSelectedFile(f12);
fileChooser.setDialogTitle("Specify a file to save");
int userSelection = fileChooser.showSaveDialog(parentFrame);
[code]....
I want to save selected text file as html file in target directory....
View Replies
View Related
May 19, 2014
which when user enter a number then will display how many * in a line .Produce a line: ***** But my code only show 1 * there... what wrong with it ?
import java.util.Scanner;
public class display {
public static void main(String args[]) {
int i,n = 0 ;
[Code] ...
View Replies
View Related
Mar 29, 2015
I have a question related to trees in Java. The following code is given:
public class BinarySearchTree {
private Node root;
public BinarySearchTree() {
this.root = null;
}
public BinarySearchTree(Node root) {
[Code] ....
The inorder-method is the one that really imports. I have to go through a tree using the Inorder-method. I do understand how this works, however I don't understand how the code fits to the inorder process. I understand the code up to the point where it reaches the most left "root", but then I do not know how to go further. How do I reach the root above then?
View Replies
View Related
May 7, 2014
Write a method that prints characters using the following: public static void printChars(char ch1, char ch2, int numberPerLine). This method prints the characters between ch1 and ch2 with specific numbers per line. Characters are separated by exactly one space.Test your method with the following main method:
public static void main(String[] args)
{
printChars(‘A’,’z’,10);
printChars(‘0’,’9’,5);
}
View Replies
View Related
Nov 8, 2014
I am a student taking a Java programming class. My assignment is to write a program that converts a roman numeral input as entered by a user and converting it to it's integer value (arabic number). These are the methods that I must have in it:
1. Write a method that takes input from the user and passes it to a conversion method.
2. Write a method that yields the numeric value of each of the letters (conversion method).
3. Write a method that outputs the number the user entered and the converted number.
4. Write a main method to test the 3 methods.
I have written the first method, at least I think. Here is what I did there:
public static String romanInput(String number) {
Scanner numberInput = new Scanner (System.in);
System.out.print("Enter a roman numeral: ");
String userInput = numberInput.next();
return userInput;
}
I returned the userInput and I think that is passing it to the conversion method? Now I am working on this conversion method and to be honest I don't know where to begin. I am told how to convert a string in my assignment by the professor. I am told:
- Look at the first two characters. If the first has a larger value than the second, then simply convert the first.
- Call the conversion method again for the substring starting with the second character.
-Add both values. If the first one has a smaller value than the second, compute the difference and add to it the conversion of the tail.
I am also told to use a single-dimensional array. But, I don't know what I am to use a single dimensional array for? So this is what I wrote so far for this method:
public static int numberConversion(int number) {
int romanConv = 0;
char[] romanNum = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
char[] arabicNum = {1, 5, 10, 50, 100, 500, 1000};
romanNum = arabicNum;
}
I have written a character array for the roman numerals, and then one for arabic numerals, then I set them equal to each other. I also declared an integer variable set to 0 because I think that is what I will be returning at the end of the method. Now I don't know where to start for the conversion algorithm here. I know this is what I have to do, but I don't know how to do it:
1. Add the numbers together if they are in decreasing value or are equal in value. For example: VI is read as 5 + 1 = 6 XVI is read as 10 + 5 + 1 = 16 XXXVIII is 10 + 10 + 10 + 5 + 1 + 1 + 1 = 38
2. Use subtraction if a number is less than the number that follows it. For example, I is less than V, so when I is in front of V, you subtract its value.
3. For example: IV is 5 1 = 4 IX is 10 1 = 9 XL is 50 10 = 40 MCM is 1,000 + (1,000 - 100) = 1,900
I can't use hashtables or enums because I haven't learned about that yet. I have a feeling I need to use a for loop. I know I haven't done any of the actual programming work but I don't know how to begin writing this conversion method.
View Replies
View Related
Oct 25, 2014
I must write a method that accepts a string and returns an int. The method should sum the unicode values of each character, so the string "ABC" should return 198. Also the only string class methods I'm aloud to use are length, charAt, and substring. I just don't know how the get the Unicode value.
View Replies
View Related
May 29, 2014
Write an instance method, contains, that has one explicit parameter of type Rectangle. The method should return true if every point of the rectangle determined by the explicit parameter is on or within the rectangle determined by the implicit parameter. It should return false otherwise.
This is what i did so far?
public boolean contains(Rectangle other) {
Rectangle intersect = Rectangle.intersection(this, other);
if ((intersect.left == this.left) && (intersect.bottom == this.bottom) && (intersect.width == this.width)
&& (intersect.height == this.height)) {
return true;
} else {
return false;
}
}
View Replies
View Related
Mar 23, 2015
How do i write a method in java that will add a <b> or <em> tag to a specific word regardless of case or punctuation for example for "run forest RUN!" adding bold to run would be
<b>run<b> & <b>RUN!<b>
public void addTag(String word, String tag) {
View Replies
View Related
Dec 3, 2014
I have understood my programming class up to this point and now I have been given a lab that I can't figure out for the life of me. Here what I have to do: Write a program that will call a method (called f) to calculate the following function" f(x)=(x^2)-16...this is what the output should be:
x f(x)
1 -15
2 -12
3 -7
4 0
5 9
6 20
7 33
8 48
9 65
10 84
I guess it also has to print this output in a table even though my professor never mentioned it. Usually
public class Lab12 {
public static int f(int x)
{
return x*x-16;
[code]....
View Replies
View Related
Apr 22, 2015
I am supposed to write a static method that simulates a flip of a weighted coin by returning either heads or tails each time it is called. The coin is twice as likely to turn up heads as tails. My idea was to of course use a random class
Random flip = new random
and somehow initialize it so 3 numbers are called and create if statements so that when 0 and 1 are called heads returns and when 3 is called tails is.How do I put all this together?
View Replies
View Related
Sep 1, 2014
I wrote this program to prompt user to enter his choice to do a i/o operation in a file. It shows error. How to clear the error. My code is:
import java.io.*;
import java.util.*;
class Files {
public static void main(String args[]) {
String n;
[Code] ....
error:
E:java>javac Files.java
Files.java:26: error: no suitable method found for write(String)
fos.write(n);
[Code] ....
View Replies
View Related
Oct 27, 2014
So I am calling this method several times and trying to write multiple records to a file. Problem is that every time I call the method it overwrites the file from before and doesn't add it.
public void fileWriterMethod() throws IOException{
RandomAccessFile raf = new RandomAccessFile(filename, "rw");
raf.writeInt(id);
raf.writeInt(existingMileage);
raf.writeInt(gasCost);
raf.writeInt(ndays);
raf.writeInt(rate);
raf.writeInt(totalCharge);
raf.writeInt(discount);
raf.writeInt(tax);
raf.writeInt(netCharge);
raf.writeInt(returnMileage);
raf.writeBytes(carName + "
");
//Closing the stream
raf.close();
}
View Replies
View Related
May 27, 2014
I'd like to know how to return a new array, I wrote in a method below the main method. I want to print the array but system.out.print doesn't work for arrays apparently. What structure i should use?
View Replies
View Related
Aug 2, 2014
Write a program to create an integer array of size 20. Then, the program should generate and insert random integers between 1 and 5, inclusive into the array. Next, the program should print the array as output.
A tremor is defined as a point of movement to and fro. To simulate it, the program will generate a random number between 0 and 19, which represents the location in the array (i.e. index number). Then, the 3 numbers to the left and right of this location should be reset to the value 0. If there isn't 3 numbers to the left and right you may assume a lesser number depending on the boundaries of the array.
Then, the final array should be printed as output. There is no user input for this program.Your program must include, at least, the following methods:
-insertNumbers, which will take as input one integer array and store the random numbers in it.
-createTremor, which will generate the random number as the location and return it.
A sample run of the program is shown below:
Sample output #1:
Array:1 2 2 3 1 5 4 2 3 4 4 2 1 1 3 2 1 4 3 2 1
Random position: 5
Final Array:1 2 0 0 0 5 0 0 0 4 4 2 1 1 3 2 1 4 3 2 1
View Replies
View Related
Mar 2, 2014
I am trying to write a byte array to a blob field in my database.
Below code is not working for me because the object is actually 902 bytes, however, the database tells me that it is 11 bytes once committed.
How to write to the blob field in my database?
Java Code:
protected void addFingerprint(byte[] fingerprintBytes) {
Statement stat;
try
{
updateQuery = "UPDATE " + currentTable + " SET CLERK_FINGERPRINT_DATA_BLOB = '"
[Code] ....
View Replies
View Related
Nov 8, 2014
So I need to generate 10 random integers in the range 1-20 but i have to store them in an array called numbers. Then I have to call a method called displayArray which displays the contents of the array and for the assignment i have to use a for loop to traverse the array. The method header for the displayArray method is:
public static void displayArray(int[] array)
This is what I have done
public class RandomIntegers {
static int numbers = 0;
public static void displayArray(int[] array) {
System.out.println(numbers + "Numbers Generated");
[Code] .....
View Replies
View Related
Jun 15, 2014
Write a method that returns a new array by eliminating the duplicate values in the array using the following method header: public static int[] eliminateDuplicates(int[] list). The thing is that I found the working solution that is written below, but how it works. How to eliminateDuplicates method done with flag and flag2.
Here is the code:
Java Code:
import java.util.Scanner;
public class Exercise06_15 {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
int[] numbers = new int[10];
System.out.println("Enter ten numbers: ");
[code]....
View Replies
View Related
Feb 7, 2015
I am passing input from the user to a method that will initialize an array of the data (scores in this case). The method is filling the entire array with the last input value.
array initializer method
Java Code:
public static float[] inputAllScores(float validScore) {
float[] diverScores = new float[7];
for (int i = 0; i < diverScores.length; i++) {
diverScores[i] = validScore;
}
return diverScores;
} mh_sh_highlight_all('java');
[Code] .....
View Replies
View Related
Feb 20, 2014
I just tried to fill an array with some numbers, calculated by a other function.I just tried to print this array as array, but it doesnt work. Maybe its just about the main method.
public static void main(String[] args) {
ggT(5);
}
public static int ggT(int a, int b) {
while(a!=b){
if(a>b) {
a=a-b;
} else {
b=b-a;
}
}
return a;
[code]....
View Replies
View Related
Aug 3, 2014
So if I assigned values in arrays like the below:
This is the method in main class:
public static void trainer(){
trainer[] trainerArr = new trainer[4];
trainerArr[0] = new trainer("Ben Yap", "Male", "Kuala Lumpur", 10000, "Yoga");
trainerArr[1] = new trainer("Wilson Ting", "Male", "Kuala Lumpur", 10001, "Kick-boxing");
[Code] .....
How can i pass these arrays into another method in the main class?
View Replies
View Related