Constructing A Data Array
Mar 29, 2015
I'm trying to construct a Java Data array that includes data like this:
private static final main_struct data_01[] =
{
{{0, 0, 0, 2}, -411.602870, {168.480000, -18433.810000, -121.620000, 0.400000, -0.180000}},
{{0, 0, 0, 4}, 0.420340, {-0.390000, 37.650000, 0.570000, 0.000000, 0.000000}},
etc...
Now, as the constructor, I'm trying:
static class main_struct
{
static int[] ilu = new int[4];
static double A;
static double[] B = new double[5];
}
I only get an error: "type mismatch: cannot convert from int[][] to Myclass.main_struct"I know I'm doing something wrong - of course..
View Replies
ADVERTISEMENT
Mar 16, 2014
Write a program to reverse sentences (demarked by a period) in a paragraph (demarked by an empty line input from the console) using any list of your choice.13. Create a vector that stores N numbers.
i need to reverse sentences in a paragraph.the sentences end with a period and the paragraph ends with a newline.
i tried to construct Vector<String> and Vector<Vector> reading input from scanner, but that didn't work because scanner skips newlines.
what should i do?
View Replies
View Related
Dec 11, 2014
I'm really trying to understand an example on how to construct a good suffix table for a given pattern. I've looked at numerous examples, but do not know where the numbers come from.
So here goes: The following example is a demonstration of how to construct a Good Suffix Table given the pattern ANPANMAN:
Index | Mismatch | Shift | goodCharShift
-----------------------------------------------
0 | N| 1 | goodCharShift[0]==1
1 | AN| 8 | goodCharShift[1]==8
2 | MAN| 3 | goodCharShift[2]==3
3 | NMAN| 6 | goodCharShift[3]==6
4 | ANMAN| 6 | goodCharShift[4]==6
5 | PANMAN| 6 | goodCharShift[5]==6
0 | NPANMAN| 6 | goodCharShift[6]==6
0 | ANPANMAN| 6 | goodCharShift[7]==6
I simply don't know how to get to these numbers.
View Replies
View Related
May 5, 2014
In this i Write a Java program to parse a syntactically correct arithmetical expression and produce an equivalent Expression TREE. Remember, in an expression tree the terminal nodes are variables and constants, and the interior nodes are operators (such as +,-,*,/). For instance the expression: (1 + 2) * 3 can be represented by the following tree:
INPUT Expression
(1 +2)*3
POSTORDER Expression
1 2 + 3 *
TREE [root=asd.reg.Node@56ddc58]
But when I Execute the program it Shows only Prefix and postfix .But the requered output is in inorder preorder and postorder ...
import ava.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.tree.TreeNode;
[code]....
View Replies
View Related
May 6, 2014
I Write a Java program to parse a syntactically correct arithmetical expression and produce an equivalent Expression TREE. Remember, in an expression tree the terminal nodes are variables and constants, and the interior nodes are operators (such as +,-,*,/).
For instance the expression: (1 + 2) * 3 can be represented by the following tree:
INPUT Expression
(1 +2)*3
POSTORDER Expression
1 2 + 3 *
TREE [root=asd.reg.Node@56ddc58]
But when i Execute the program it Shows only Prefix and postfix .But the requered output is in inorder preorder and postorder so how to solve these error
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import javax.swing.tree.TreeNode;
public class InToPost {
private static String str;
[Code] .....
View Replies
View Related
Feb 6, 2015
How do I pass the data within an initialized array from inside one method to another method of the same class? Will I need to return the array, assigning it to a temp array, which will then be passed as an argument to the other array? The idea is to create an array for an entire year, and be able to manipulate or edit data for a particular month using the other method.
public class Temperature {
static Scanner input = new Scanner(System.in);
static String [] monthArray = {"January", "February", "March", "April", "May",
"June", "July", "August", "October", "November", "December"};
public static void main(String[] args) {
[Code] .....
View Replies
View Related
Dec 4, 2014
if there was a way to copy specific array info into a temp array with more concise code?
This is the code I have for instance:
tempList[0] = myCube.orange[2];
tempList[1] = myCube.orange[5];
tempList[2] = myCube.orange[8];
tempList[3] = myCube.blue[6];
tempList[4] = myCube.blue[7];
tempList[5] = myCube.blue[8];
But isn't there any way I could just condense it to be like:
tempList[0,1,2] = myCube.orange[2,5,8];
It would save me from 72 lines of code down to 24 if I could rock it all on one line.
View Replies
View Related
Apr 23, 2014
I want to keep count of how many students are in my array. the array i made up of objects from other classes. like the class Student how do i do this. i have tried contains but better way it to to a loop to go through the array and determine if each object is a particular type but i don't know how to do this. here is the code
import java.util.*;
import java.util.ArrayList;
public class Driver {
public static void main(String[] args){
/* Comments required
PersonFileReader pfr = new PersonFileReader("person.dat");
ArrayList<Person> testData = pfr.readData();
Database db = new Database(testData);
[Code] .....
View Replies
View Related
Oct 10, 2014
i need to create an array with attributes name, gender, phone, age.and then sort acording to age in ascending order.
i created like this,
public class Array{
private String[] name={"ram", "katy", "priti", "john"};
private String[] gender={"male","female","female","male"};
private int[] phone={989898089,89898989,8982989089,898908989};
private int[] age={45,24,30,28};
public void printarray(){
[code]....
This code sorts the age attribute alone and when printing ouput it swaps one person's age to other person, how to make it correct
View Replies
View Related
Jun 2, 2014
the problem I'm having is I want to use a mutator method to set data for an array element. The code I have so far is:
public void addProduct(String productName)
//Goes through and sets the name of a product and assigns it to the array
{
int index;
for (index = 0; index < product.length(); index++)
{
product[index].setName(productName);
numberOfProducts++;
}
}
The array was initialised like this:
Product[] product = new Product[3];
And the setName(String) method is just your typical mutator method.However, in Eclipse, I have an error messages. It is:
"-The method setName(String[]) is undefined for the type String" .....
View Replies
View Related
Jun 5, 2014
I can read the data to a monitor perfectly. But, I'm having problem reading data from an external file into an array of class objects. Here's my attempt at writing the method:
private void openFile()
//This method asks the user to enter a file name(including the file extension) and then
//Sets the data to an array of Product type {
String fileName, storeName="", emptyLine1="", emptyLine2="", name="", productName="";
int demandRate=0;
double setupCost=0.0, unitCost=0.0, inventoryCost=0, sellingPrice=0;
Scanner inputStream = null;
[code]...
View Replies
View Related
Jul 1, 2014
I am working on a simple JAVA tutorial, not homework, where employee data is taken from an array and displayed on the console. The data is divided by department, age, name and for the Accounting and Information Systems departments, they are displayed in ascending order by employee age. Everything works except I am not getting the output to the console other than the titles. As I step through the debug, the data clearly is populating the array.
Here is my code:
Company Class:
package SimpleJavaAssignment;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
[Code] .....
Prime Age Checker:
package SimpleJavaAssignment;
import java.math.*;
public class PrimeAgeChecker {
public boolean PrimeAgeChecker(int age) {
BigInteger bi = new BigInteger(String.valueOf(age));
boolean prime = bi.isProbablePrime(10);
return prime;
}
}
View Replies
View Related
Aug 5, 2014
how to index the arrays so that i can choose specific data so that averages and maximum and minimum values can be worked out. My code is below
package weatherProgramPackage;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
[code]....
View Replies
View Related
Jul 24, 2014
I set the limit to 2 so the producer blocks after two insertions until an item is consumed. Because we are dealing with a basic counter that increments, we do not lose any data. Since after queue is freed up we simply increment by 1, so we are able to store all numbers. However, in real world situation, you might be storing data coming from redis server into the queue. And redis server may be publishing a plethora of data. So when the queue blocks, and new data comes in, what happens? Is the currently blocked data lost forever and the new data that came in is now blocked, or is the new data that came in ignored and the old data remains being blocked until queue is freed up?
Java Code:
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
public class BlockingQueueBlocking {
private BlockingQueue<Integer> sQueue = new ArrayBlockingQueue<Integer>(2);
int counter=0;
private void test() throws InterruptedException{
[code]...
View Replies
View Related
Jun 2, 2014
My assignment was to create a class and then write a program that uses the methods of the class I created. All the output is correct except for the Question # Missed. It prints [I@1dd0fe7. The wrong question numbers have to be stored into an array and that array printed. I've tried using a for loop to print, rearranging the code, setting the code to how I did in the other methods. I either get this [I@1dd0fe7 -or- a bunch of 0's. I'm not sure if I am calling the method incorrectly, or just do not have the correct set-up to print the array, or if I am just not grabbing the ones that are incorrect.
public class DriverExam {
// Fields
private boolean result;
private int testTotal;
private int numWrong;
private int [] numMissed;
private char [] answerKey;
[Code] ....
View Replies
View Related
Mar 9, 2014
TL,DR: observe the nodes just below, that is the data each node in the link list contains. How do I iterate through the entire list to reach the last element (H), so I can add an element right after it?
So I have 4 nodes doubly linked with two dummy nodes for head and tail:
head
node1 = {A}
node2 = {null, B}
node3 = {C, null, D, E}
node4 = {null, F, null, G, null, null, H, null}
tail
Ok, so since the list only contains 8 elements that are not null, its size is actually 8 correct? So now lets say I have an add method that has
add(E item) and inserts the item at the end of the list. So I can get to the last node with tail.previous(), but then how do I iterate to the end so I can add the item after the last item in the list (H). I guess I don't know how you only access one nodes data when that data is an array with empty spaces.
Here is the entire Node code:
Also, I can't just iterate through the whole thing because I am not supposed to. I am supposed to just find the right node and iterate through that only.how to maneuver around a linked list containing nodes where each node contains an array.
/**
* Node class that makes up a DoublingList. Feel free to add methods /
* constructors / variables you might find useful in here.
*/
public class Node<E> {
/**
* The node that comes after this one in the list
[code]....
View Replies
View Related
May 22, 2014
How to modify and delete data from a array list in net-beans?
View Replies
View Related
Feb 11, 2015
So I want to write a constructor that creates a new object with the data from the array values. I don't know where to start. It's the last method in the code:
public class Measurements {
private double[] values;
private double[] newArray;
private int n; //numberofvalues
private double[] ms;
public Measurements(int max) { //constructor
[code]....
View Replies
View Related
Mar 16, 2014
I'm trying to return an array back to main. The array returned to main should contain the reversed random numbers array. I believe I have the array correctly reversed within the 'reverseArray' method. I'm trying to send this array back to main, but it appears to contain empty data (a bunch of zeros).
Java Code:
class ArrToMain {
public static void main(String[] args) {
final int NUMBER_OF_ELEMENTS = 1000;
double[] numbers = new double [NUMBER_OF_ELEMENTS];
//Invoke initialize method
initialize(numbers);
[Code] ......
View Replies
View Related
Mar 17, 2015
public class InputFileData {
/**
* @param inputFile a file giving the data for an electronic
* equipment supplier’s product range
* @return an array of product details
* @throws IOException
*/
public static Product [] readProductDataFile(File inputFile)
throws IOException{
// YOUR CODE HERE
}
This code is meant to be used to read a text file and store the data in an array of type Product[]. I know how to read in a text file and have it sort it into an array, but I've never seen code laid out in this fashion before (specifically "public static Product[]", and I'm unsure how to work with "(File inputfile)". I've looked all over the place but can't find any examples of anything like this.
Also, the code given cannot be changed, as it's that code I have to work with.
I still don't understand how to use it as a whole. For example, do I read the file in the main and have this method read that in and output to the Product class? Do I read the file in this method? I can't work out how to make this work when I have to use this method.
View Replies
View Related
Nov 15, 2014
I'm trying to figure out the necessary code for reading integers from a text file, then placing them withing the two-dimensional array I have created, and then finally printing the array using a nested for-loop. I have attached the file I would like to read from. I'm having trouble figuring out how to reference the text file with the integers, and also how to properly create a dynamic preface for each row of the array. I want the preface to display as "Week #: ", with # being the row number. I tried to create an integer to be used that way, but NetBeans tells me whatever integer I declare has already been defined in method main. I know I need to use scanner to read the file. I would like the output to display like this:
Quote
Temperature Data
Week 1: 73 71 68 69 75 77 78
Week 2: 76 73 72 72 75 79 76
Week 3: 79 82 84 84 81 78 78
Week 4: 75 72 68 69 65 63 65
View Replies
View Related
Aug 22, 2014
Conditions : Need to print all the inputted data(name,score) and the average.
import java.util.Scanner;
public class Case2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] score = new int[5];
String[] name = new String[5];
int ave = 0;
[Code] .....
View Replies
View Related
May 6, 2014
I'm trying write a Dijkstra's implementation in java. First off, here is the algorithm:
package lab3;
import java.util.HashMap;
import java.util.Stack;
/**
* Compute shortest paths in a graph.
*
* Your constructor should compute the actual shortest paths and maintain all the information needed to reconstruct them. The returnPath() function should use this information to return the appropriate path of edge ID's from the start to the given end.
*
* Note that the start and end ID's should be mapped to vertices using the graph's get() function.
*/
class ShortestPaths {
Multigraph graph;
final int INF = Integer.MAX_VALUE;
PriorityQueue<Integer> Q;
[Code] ....
I followed someone else psuedocode very closely but for whatever reason, my edge[] array is just full of null data, which means I can't actually return the shortest path. Why that's happening/how to fix it? Maybe I'm not understanding dijstra's correctly.
View Replies
View Related
May 8, 2014
How i can get the data from a file, for a key that have multiple values without using split method and i want to store that data in an array
file name:"new.txt"[contains below data]
Name=google.com, yahoo.com,facebook.com
Attachment=abc1,abc2,abc3
I am successfully able to do this using following code
Properties props = new Properties();
String configFilePath = (Cjava_confignew.txt);
props.load(new FileReader(configFilePath));
String TestName = props.getProperty(Name);
String test[] = TestName.split(,);
Now i just want to store the values for key "Name" in array without using TestName.split(,); but i am not able to do this.
I have also used .yml file to avoid this but did not succeed, some way to do this
file name test.yml
Name
-google.com
-yahoo.com
-facebook.com
Attachment
-abc1
-abc2
-abc3
i want to store multiple values for single key(Name) within the array
View Replies
View Related
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
Apr 15, 2014
I have to make two classes. The first one crates an instance of an array of several integers and prints data (average, greatest, lowest, et cetera) based on the second class, which contains the methods. I'm having a problem with the syntax for the first class required to use the methods.
Here's a shortened version of what I have right now just based on processing the number of integers in the array (because if I can get just one method properly connected, I could figure out everything else).
Driver
import java.util.Arrays;
public class ArrayMethodsDriver
{
//Creates the ArrayMethods object
public static void main(String[] args)
{
int[] a = {7,8,8,3,4,9,8,7};
[Code] ....
When I try to compile this, I currently get the "class expected" error on the count part.
View Replies
View Related