Working With Parallel Arrays
Dec 5, 2014
The assignment was to create 3 parallel arrays to make a student database.The first array will contain 4 digit student id's, the second a string array with student names, and the third array is student gpa's. The user is to receive a dialog box asking to enter the student id, and if the id is correct the user is to see the student name and grade. If the user input does not match any value in the student id array, the user is to receive a message stating invalid id. Here is the code I have so far.
For some reason no matter what the user enters, the information for the last array entry is displayed.
public class parallelStudent
{
public static int sequentialSearch(int[] array, int value)
{
int index; //loop control variable
int element; //element the value is found at
boolean found; //flag indicating search results
[code]...
View Replies
ADVERTISEMENT
Mar 26, 2015
how to loop my arrays, so when I sort them (highest/lowest) the 2nd array corresponds to the sorted array
import java.util.Scanner;
import java.util.Arrays;
public class ArraysArrays {
public static void main (String[] args){
[code]....
View Replies
View Related
Mar 30, 2014
I am trying to sort a set of parallel arrays. I really believe that the code is correct, but it is not working out as expected.This is the specific code for the sort:
Java Code: for (int y = 1; y < (dataArray.length + 1); y++)
{
for (int x = 0; x < dataArray.length - 1 ; x++)
{
if ((dataArray[x][1]) <= (dataArray[x + 1][1]));
{
tempOpen = dataArray[x][1];
dataArray[x][1] = dataArray[x + 1][1];
dataArray[x + 1][1] = tempOpen;
[code]....
View Replies
View Related
Mar 8, 2015
I'm building a text based "game" where you are communicating with this android creature called Gargoid , at a VERY primitive level . how it works is, simply the user type in a sentence which is decoded for meaning by comparing it with a built in list of words in order to figure out what the user is saying, and then reply with a a relevant response also from a list of built in words. the whole thing would look something like this,
user: what is your name
Gargoid : my name is Gargoid, nice to meet you
user: how is the weather
Gargoid: the weather is wonderful
so far I have 11 arrays which are the following
String[] for user typed in words used for comparison to find meaning ..An Array of String[] , 7 so far, to hold what I call the Gargoid dictionary for example String[] greeting={hi,hello,aloha}, words that indicates greeting int[] called frequency to determine which of the 7 arrays have the greatest "relevancy" to what is being said. and finally another String[] for responses here's the actual code, I want you guys to tell me if there's a way to reduce all this never ending number of arrays? and also is this code a good application of object oriented programming?
MainClass
public class GargoidMain {
public static void main(String[] args) {
TheKeyBoard keyboard=new TheKeyBoard();
TheTranslator translator=new TheTranslator();
TheBrain brain=new TheBrain();
translator.translate(keyboard.userSaysWhat());
brain.respond(translator.userSays());
[code]....
View Replies
View Related
Dec 1, 2014
This is my code.
public class PA9 {
public static void main(String[] args) throws FileNotFoundException {
// create data file to read from
File inf = new File("cityPopulationData.txt");
//Create a file to write out to.
PrintWriter fileOut = new PrintWriter("output.txt");
[Code] .....
This is my error
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:909)
at java.util.Scanner.next(Scanner.java:1530)
at java.util.Scanner.nextInt(Scanner.java:2160)
at java.util.Scanner.nextInt(Scanner.java:2119)
at PA9.getData(PA9.java:35)
at PA9.main(PA9.java:22)
View Replies
View Related
Dec 1, 2014
Write a Java program to read from the data file, find the city with the highest population based on the 2010 census data, the city with the highest population growth from 2010 to 2013, the city with the lowest population growth from 2010 to 2013, and the city with the highest density (number of persons per sq. mile).
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
[code]....
View Replies
View Related
Dec 24, 2014
I am trying to use parallel arrays to store names and job titles, then display the name/job title combo depending on which is entered. I have always struggled with arrays, so I'm sure that's where my issue is, but I am not sure how to resolve this one. I tried to use the toString() method with the jobs to see if that would allow the job title to match to one of the titles listed, and I tried to not use the toString() method with the names to see if that would allow the name entered to match to one of the names listed in the array. Both options only display the "invalid" message no matter what I enter. What would be the best choice to use the arrays to properly display the information ....
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JEmployeeTitle2 extends JApplet implements ActionListener
{
Container con = getContentPane();
[Code] .....
View Replies
View Related
Sep 6, 2014
So in my parallel array i read from a textfile of strings and if i enter the string into the string array and if strings are repeated i store it in a parallel array that counts repeated instances. I'm supposed to get 27 15 21 23 20 but instead i get 106 0 0 0 0....
Scanner sc=new Scanner(new File("Cat.txt"));
String category=sc.nextLine();
int total=sc.nextInt();
int[]totcat=new int[total];
String[]names=new String[total];
while(sc.hasNextLine()){
[Code] .....
View Replies
View Related
May 11, 2015
I've been working on a question using parallel arrays where the user inputs an integer 1-12 and the output will be the name of the month and the number of days in that month. This is what I have so far
import java.util.*;
public class DaysMonth
{
public static void main (String args[]) {
Scanner keyIn = new Scanner(System.in);
int[] days = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
[Code] ....
After I enter the user int it just ends.
View Replies
View Related
Jun 28, 2014
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.
View Replies
View Related
Sep 15, 2014
I'm currently starting my thesis where my Project will involve creating a diff and merge tool for simulink slx files. These are built using several xml files, a png and sometimes some other data files. One can get to these files by changing the file extension to zip.
I am a bit troubled by this since I want to be able to handle all these files simultaneously and hence need to do this automatically when choosing the slx file.
View Replies
View Related
Apr 13, 2015
I'm having an issue with using a JComboBox to select an item from a parallel array and displaying the correlating results in the same frame. Essentially, I have to add seven cities to a JComboBox drop down within a frame, select a city then display the population of that city in the frame with a label indicating the population. I have two issues:
1) my label text will not show up during execution unless I drag a corner no matter what width or height I make the frame.
2) I need to make the JComboBox selection correlate to the city population and display as a label, not having making that work using the getSelectedIndex() method.
I think I need to add an event listener for the combobox selection, not sure where to add that if that is the case. Here is my mess so far:
import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JComboBox;
[Code]....
View Replies
View Related
Apr 13, 2015
I'm having an issue with using a JComboBox to select an item from a parallel array and displaying the correlating results in the same frame. Essentially, I have to add seven cities to a JComboBox drop down within a frame, select a city then display the population of that city in the frame with a label indicating the population. I have two issues:
1) my label text will not show up during execution unless I drag a corner no matter what width or height I make the frame.
2) I need to make the JComboBox selection correlate to the city population and display as a label, not having making that work using the getSelectedIndex() method.
I think I need to add an event listener for the combobox selection, not sure where to add that if that is the case. Here is my mess so far:
import java.awt.FlowLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class JPopulation{
public static void main(String args[]) {
[Code] .....
View Replies
View Related
Jul 31, 2014
I've been wondering about this for a while. Is there any way to parallel I/O operations or is this a bad idea? If you could create two lists of good and bad ways to parallelize I/O.
View Replies
View Related
Feb 21, 2015
I have to write a program that calculates the average temperature for a month using parallel arrays (it is mandatory to use a parallel array). I'm new to Java (I'm more familiar with C++) so I get confused with the use of methods. I know how to compute the averages already, I just setting up the parallel arrays. This is what I have so far:
Java Code:
import javax.swing.*;
import java.util.Scanner;
public class Temperature {
public static void main(String[] args) {
String[] day = {"Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Sunday"};
int[] temp = new int [7];
[Code] .....
For now I just want to show the contents in my array before I start computing averages.
View Replies
View Related
Mar 8, 2015
I am having an issue with a parallel array that I created that returns array values based on an input. The code only works for the first four array locations just fine. The remaining values are not found. I thought it might be a memory allocation issue with the array size, I tried to dimension the array, however, using the Eclipse editor get errors.
import java.util.*;
import javax.swing.JOptionPane;
public class StudentIDArray {
static String[] studentNum = new String[]
{"1234", "2345", "3456", "4567", "5678", "6789", "7890", "8901", "9012", "0123"};
static String[] studentName = new String[]
[Code] .....
View Replies
View Related
Feb 9, 2014
Judges are scoring divers and I need to create a table of scores for each diver given by 7 judges. In the second for statement, I want
Java Code: for(int column = 0 ; column < judges[row].length ; column++) mh_sh_highlight_all('java');
to be
Java Code: diver[row].length mh_sh_highlight_all('java');
Instead of judges. Because the total number of divers would like exceed the number of judges, and I believe this is limiting the number of columns to the number of judges. When I use divers though, an error occurs, saying that "int cannot be dereferenced".
Java Code:
public float inputValidScore(){
int Num_Judges = 7;
System.out.print("Enter number of contestants: " );
int diver = input.nextInt();
float [] [] judges = new float[Num_Judges] [diver];
[Code] ....
The above is just a method within the rest of the code.
View Replies
View Related
Jun 11, 2014
You are to write a parallel program that will receive a large array of unsorted integers containing digits from 0 to 99. The program will have to calculate the SUM and AVERAGE of ODD number digits between 25 and 75 (inclusive). The user may specify the size or the array and the total processor that the machine has. The size of the array must be divisible by number of processor. Based on the given size, the computer will generate random integer numbers automatically to populate the array.
The program should display the status of the calculation for each processor. The result should be displayed after all calculations are completed.Error messages should be displayed appropriately
a) Write a sequential (non-parallel) program that will accomplish above task.
b) Write a concurrent (parallel) program that will produce the result of the above task.
View Replies
View Related
Apr 10, 2014
I am developing an application to share my client screen with server, it is working well on swing. But i want to develop as web application, i am trying to using applet. But i am facing the fallowing problem..,
1) The Applet screen also open and project also running well on server mechine. But unable to see the client screen on the server.
2) The problem may be to display the JDesktopPane or JInternalFrame.
My working Server Code extends withe JFrame..Java Code:
package remoteserver;
import java.awt.BorderLayout;
import java.awt.Container;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JApplet;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
[code]....
View Replies
View Related
Apr 23, 2015
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?
View Replies
View Related
Sep 19, 2014
How do i increase the size of a 2D array from 2X2 to 4X4 where only the boundary elements are zeroes and the rest of them remain the same?
View Replies
View Related
Jan 28, 2015
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
[code]....
View Replies
View Related
Aug 22, 2014
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,
View Replies
View Related
Nov 22, 2014
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).
View Replies
View Related
Mar 15, 2015
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.
View Replies
View Related
Sep 21, 2014
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;
}
[code]...
View Replies
View Related