Loops For Parallel Arrays

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


ADVERTISEMENT

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 View Related

Sort A Set Of Parallel Arrays

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

How To Reduce Number Of Parallel Arrays In Code

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

Getting Error On Java Code Using Parallel Arrays

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

Getting Error With Java Code - Using Parallel Arrays

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

Using Parallel Arrays To Store Names And Job Titles Then Display Combo Depending On Input

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

Compare Two Different Arrays From Separate Loops

Oct 21, 2014

I am working on an assignment that is to simulate the relationship between a cache and main memory. Basically it is supposed to be a 16 slot cache and we are to have 500 for main memory. I need it to compare the corresponding index for both arrays, then go through then repeat the cache array and compare it to the next 16 of main memory. It is to simulate an direct mapped cache. How to compare two arrays from separate loops.

public class MainMemory {
private short mainMem[] = new short[200];
public void assign(){
short i;
for ( i = 0; i < mainMem.length; i ++){
mainMem[i] = i;

[Code] .....

View Replies View Related

Parallel Arrays - User Input Integer 1-12 / Output Name Of Month And Number Of Days In That Month

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

What Is The Difference Between Regular Arrays And Multi Dimensional Arrays

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

Parallel Manipulation Of XML Files

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

JComboBox Using Parallel Array

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

JComboBox And Parallel Array

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

I/O / Streams :: Any Way To Parallel I/O Operations

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

How To Display Contents In Parallel Array Using Java

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

Parallel Array Recall - Return Value Based On Input

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

Parallel Array Format - Judges Scoring Contestants

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

Parallel Program - Calculate SUM And AVERAGE Of Odd Number Digits Between 25 And 75

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

Counting Repeated Instances - Parallel Array Is Not Working Correctly

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

JSP :: Loops In Dropdowns

Dec 5, 2014

I'm working on an old site that we have, I'm adding a couple dropdowns to our forms.With a connection to our database I can pull in values for selBaseCurr, But it's not pulling any values into the second dropdown for selTargetCurr...Am I missing something in the while loop?

<select title="Select currency to convert from" id="selBaseCurr" name="selBaseCurr">
<% while(rs.next()){%>
<option value=""><%= rs.getString("CURR_CODE") %></option>
<%} %>
</select>
<!-- /base -->

[code]....

View Replies View Related

Do While Loops With Chars?

May 28, 2014

here I have a do-while loop. When I push a button, then press enter, the program should do stuff, then ask me for another key. If I press any key but q, it repeats itself. If I press q then enter, it should end the loop. But then when I press q then enter, it still does the functions in the do-while loop.

Java Code:

Scanner kb = new Scanner(System.in);
System.out.print("Press any key to start.");
String letter = kb.next();
do
{
stuff
System.out.print("Press any key to call another number or press "q" to quit.");
letter = kb.next();
}while(!letter.equals("q") || !letter.equals("Q")); mh_sh_highlight_all('java');

View Replies View Related

While Loops Within If Else Statements?

Dec 19, 2014

What I'm trying to do below is to say if (adultTickets > 0) I want to bypass the studentOAP tickets question and go straight to the question about dinner. But if (adultTickets ==0) I want to go to the studentOAP question and then if the (studentOAPTickets >0) to go to the question about dinner. But if the (studentOAPTickets ==0) I want to go straight to the question about the contact number.

System.out.print("How many adult tickets do you require? ");
int adultTickets = 0;
boolean validAdultValue = false;
while (validAdultValue == false) {
if(aScanner.hasNextInt())

[Code] ....

View Replies View Related

For Loops With If Statement?

Nov 21, 2014

i'm confused about the if statement part because int i = 0 is set to zero but how can you get the remainder if int i is zero?

for (int i = 0; i < 200; i++) {
if (i % 12 == 0) {
System.out.println("#: " + i);
}

explain to why it output like this?

#: 0
#: 12
#: 24
#: 36
#: 48
#: 60
#: 72
#: 84
#: 96
#: 108
#: 120
#: 132
#: 144
#: 156
#: 168
#: 180
#: 192

View Replies View Related

While Loops And Strings

Jan 3, 2014

So the while loop I am trying to use is:
while( type != "EXIT" ) {
type = input.next();
}

The problem is that typing in EXIT doesn't end the loop like I want it to. I also tried input.nextLine(); but neither of them work. The loop is being used to fill an ArrayList so the number of elements can change based on how many they want. What am I doing wrong, or what alternatives do I have?

Seems I need to use !type.equals("EXIT")

View Replies View Related

Nested For Loops

May 15, 2014

how a nested for loop increments the outer loop and then the inner loop and then when it runs the inside code.I've ran the program a few times but I'm just not understanding it, need little narrative to it?

for(int i=0; i < 5; i++){
System.out.println("i - " + i);
for(int j=0; j < i; j++){
System.out.println("j - " + j);
count++;
}
}

View Replies View Related

Integer Or Int For Loops

Mar 4, 2014

I would like to know which one is more appropriate to use in "for" loops or "while" loops.I don't know exactly when to use Integer or int.

for(int i=0; i<10; i++){ ... }
for(Integer i=0; i<10; i++){...}

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved