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


ADVERTISEMENT

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

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

JSF :: Select Button To Display Contents Of Column Of Specific Row

Dec 18, 2014

Example of my table.Head1Head2 Head3Head4 ( table headers )

“R1C1”“R1C1”“R1C1”“R1C1”
“R2C1”“R2C1”“R2C1”“R2C1”
“R3C1”“R3C1”“R3C1”“R3C1”

Below is a snippet from DataTable component to display the contents of the “Head4” column.

<p:column headerText="Head4" style="width:150px;height:8px" >
<h:outputText value="#{message.data}" />
</p:column>

All the entries in the table are of type String.However, the String content for the “Head4” column can be very larger and displaying this makes the table very large.As an alternative, is there a way to provide a button for the “Head4” for each row and when the user selects the button on that row, the corresponding “Head4” column contents is displayed in a pop up dialog box ? I am using Primefaces 5.0.

View Replies View Related

Display Contents Of File In Reverse Order - Output To Console

Jun 24, 2014

Create a class that allows the user to select a file and output the contents of the file to the console. Recommend using a text file to display, java files are text files. You may want to put this code in a method to allow you to complete the remainder of this assignment without overwriting your code.

- You should ask the user to enter the full path to your file to make certain you are processing the correct file.

- Modify your code/add a method to display the contents of the file in reverse order. You do not need to reverse the characters on each line but simply output the lines of the file in reverse order.

Hint: read the content of the file into an ArrayList and then traverse the ArrayList.

this is what i go so far.

package classActivity;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Select
{
public static String enterFilePath()

[Code] ....

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

Swing/AWT/SWT :: Display Two JtestAreas Contents Alternatively Handled By EventQueue-0 Thread

Jan 7, 2015

I'm developing Chat application GUI using SWING. My GUI has two JtestAreas one for displaying message that i was sent, and another for displaying replay coming from server. I was used Thread.sleep(1000) after message sent . Due to that, AWT-EventQueue-0 thread stops to display send message in first JtextArea and waits until it get response from server. After got response from server, in one shot, My GUI displays both JtetAreas Content.

But, I need to display send Message and Response Message in two different shots. I know the reason why it displays in one shot.

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

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

Trying To Display Array Results In GUI Window JAVA

Sep 16, 2014

I am having the hardest time trying to figure out how to display an array in a 1-window GUI.

I can display 1 book separately, by basically ignoring the array and creating a new object for each book, but I need all 5 books to display in one window, and that's where I'm lost. I'd really like to use the arrayI built to generate the books in the GUI. The information of each book appearing horizontally, and the different books appearing vertically.

// Bookstore.java
// This program displays information on multiple books

/* Currency Formating Import */
import java.text.NumberFormat;
import java.util.Locale;
import java.util.Arrays;

[Code] ....

View Replies View Related

Function That Will Add Contents Of String Array

Sep 18, 2014

Write a function that will add the contents of a String array.

1. This time the input array to your function will be an array of Strings.

2. Your function body will be similar except you'll have to convert each String to a double number.

public class SumVals2 {
String aryVals[];
double result;

[Code]....

View Replies View Related

Not Printing Contents Of Array With Spaces And Commas

Nov 7, 2014

public class ArrayPrinter {
public static void main(String[] args) {
int[] oneD = {5, 6, 7, 8};
PrintArray(oneD);
}
public static void PrintArray(int[] Arr) {
System.out.println ('[');
for (int i =0; i >= Arr.length; i++) {
System.out.print (Arr[i]);
if (i < Arr.length){
System.out.print(", ");
}
System.out.print (']');
}
}
}

I tried to format this to enhance readability but I'm not sure if I managed to improve it any... This code should be printing the contents of the array with spaces and commas its just printing [. I think this is because Arr is empty for some reason but I'm not sure why it would be when it gets the values of oneD passed to it.

View Replies View Related

Array Setup - Analyze By Adding Up Contents Of Each Column

Feb 16, 2015

I've setup an array that I would like to analyze by adding up the contents of each column, however, the out of bounds exception pops up when I try to execute the program. I know the book usually expresses this operation the other way around, where the row is the argument of the first for statement, but I've set my array up where I need to add each row before moving to the next column.

vowelCounter is a 5x3 array.

// Display the line which had the most number of vowels

public static int maxVowelSentence() {
int max = 0, sum = 0;
int sentence = 1;
for (int row = 0; row < vowelCounter.length; row++) {
max = vowelCounter[row][0];

[Code] ....

View Replies View Related

Open A File And Store Contents Into A Two Dimensional Array

Feb 11, 2014

So I am trying to open a file and store the contents into a two dimensional array. I seem to have no problem using this same basic code to read the file and output it. But when I try to change it so that all the data is stored into the array, it does not work.

Java Code:

public void convertFile()
{
String filePath = ("C:UsersBradDownloadsFB1.csv");
String [][] rowCol = new String [429][6];
try
{
BufferedReader br = new BufferedReader(new FileReader(filePath));
StringTokenizer st = null;
System.out.println("Your file is being converted to an array. This may take several minutes.");

[code]....

View Replies View Related

Program Should Read File Contents And Store Information In Array Of Golfers

Dec 3, 2014

The main method will drive your program by doing the following:

-Create an array to hold all the individual golfers and par scores (type is Golfer[ ]).
-Prompt the user for a data file containing the Par scores and the player names and score. The format of the input file should look like

Par, 3, 4, 4, 3, 4, 3, 5, 3, 4
George, 3, 3, 4, 3, 4, 2, 3, 3, 4
Paul, 4, 5, 4, 3, 6, 3, 4, 3, 5
Ringo, 3, 3, 4, 3, 4, 2, 4, 3, 4
John, 4, 4, 4, 3, 4, 2, 5, 3, 4

Your program should read the file contents and store the information in your array of Golfers.

View Replies View Related

Floating Point Numbers - Print Contents Of Array In Reverse Order

Feb 27, 2014

I am trying to do this assignment but I can't get the needed output.

Create a program that asks the user how many floating point numbers he wants to give. After this the program asks the numbers, stores them in an array and prints the contents of the array in reverse order.

Program is written to a class called ReverseNumbers.

Example output

How many floating point numbers do you want to type: 5

Type in 1. number: 5,4
Type in 2. number: 6
Type in 3. number: 7,2
Type in 4. number: -5
Type in 5. number: 2

Given numbers in reverse order:

2.0
-5.0
7.2
6.0
5.4

Java Code:

import java.util.Scanner;
public class apples {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
double[] numbers;

[Code] .....

View Replies View Related

How To Print Contents Of Java Bean

Mar 24, 2015

I'm trying to debug a program and I need to see the values in a Bean. I tried

" system.out.println("OrderManager.java: packagePricing, packBean= "+packBean);"

but that just gives me

"OrderManager.java: packagePricing, packBean=com.voxportal.web.device.PackageBean@73dde7ae"

which I think is a reference to the bean but not the actual contents of the Bean.

View Replies View Related

How To View Contents Of ISO File In Java

Jul 15, 2014

Any method of viewing the contents of an .ISO in java. my searches so far have said to use the java api loopy but I cant find hardly any information on it and i have been unable to use it correctly so far. If there is no way to just view the .ISO file contents then extracting its contents and then viewing them would also be fine how to do that.

View Replies View Related

How To View Contents Of ISO File In Java

Jul 15, 2014

Any method of viewing the contents of an .ISO in java. my searches so far have said to use the java api loopy but I cant find hardly any information on it and i have been unable to use it correctly so far. If there is no way to just view the .ISO file contents then extracting its contents and then viewing them would also be fine ....

View Replies View Related

How Java Finds Jar Contents Imported In A Source File

Feb 10, 2015

how java imports libraries from a jar file inside a source. Let's say I have the following code on Something.java file,

import com.mycomanyA.*;
import com.mycomanyB.*;
public class Something{
public static void main(String ... args){
// code goes here...
}
}

And the Something.java is inside the following structure...

A.jar
com/
mycompanyA/
A.class
Another.class
B.jar
com/
mycompanyB/
B.class
neededImage.gif
bin-folder/
org/
apache/
Something.java

To compile this code(Something.java) from command line I want to use the following command,

javac org/apache/Something.class

And for the compilation to be successful, I'll have to be just above bin-folder because...

- > Only then my default class path will be (.) and java would automatically include A.jar and B.jar(the other way is to add the jar files using -cp argument, which I want to avoid in this scenario)

- > And for the import org.mycompanyX to work I'll have to be in the (.) directory.

Are my assumptions correct about how java find jar contents imported in a source file?

View Replies View Related

Generate 10 Random Integers / Store In Array And Then Calling A Method To Display Array

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

Populate Array Using Nested Loops With Letter From A Until Y And Display Array To Screen

Nov 15, 2014

We were given a class lab that asks us to write a program that create a multidimensional array ( 5 x 5 ), populates the array using nested loops with letter from A until Y, and displays the array to the screen. and the result should look like this:

A B C D E
F G H I J
K L M N O
P Q R S T
U V W X Y

How to write this program.. I have tried all my best but the results are not coming like this..

View Replies View Related

JButton Cycling - Display Whole Array Instead Of Just Next Array Position

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







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