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
ADVERTISEMENT
Oct 29, 2014
I'm trying to get the program to roll a four sided die between 100 and 1000 times, depending on your input, and then displaying the answer.
public class Lab08
{
public static void main(String[] args)
{
int v1 =0, v2 = 0, v3 = 0, v4 = 0;
int n;
char response;
System.out.print("Enter number of rolls (100-1000): ");
[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
Dec 4, 2014
I need to populate a table with user input text, and selection from a combo box.
View Replies
View Related
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
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
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
Apr 15, 2014
The program should has the output depending the number I'll input. (The number should be from 1-9) . This is the program's output should be:
Input number: 4
Output:
# # # 1 # # # # #
# # # 2 # # # # #
# # # 3 # # # # #
1 2 3 4 5 6 7 8 9
# # # 5 # # # # #
# # # 6 # # # # #
# # # 7 # # # # #
# # # 8 # # # # #
# # # 9 # # # # #
(Example 2):
Input numbers: 8
Output:
# # # # # # # 1 #
# # # # # # # 2 #
# # # # # # # 3 #
# # # # # # # 4 #
# # # # # # # 5 #
# # # # # # # 6 #
# # # # # # # 7 #
1 2 3 4 5 6 7 8 9
# # # # # # # 9 #
(Example 3):
Input number: 5
Output:
# # # # 1 # # # #
# # # # 2 # # # #
# # # # 3 # # # #
# # # # 4 # # # #
1 2 3 4 5 6 7 8 9
# # # # 6 # # # #
# # # # 7 # # # #
# # # # 8 # # # #
# # # # 9 # # # #
I'm not asking the code to make this program, I have trouble to understand the algorithm to make this program ...
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
Dec 2, 2014
Recently I have missed a few weeks of my class due to family emergencies. Because of this I have missed very important lectures. My professor has assigned me the following assignment:
Prices Write a Java program that specifies three one-dimensional arrays names price, amount, and total. Each array should be capable of holding 10 elements. Using a loop, input values for the price and amount arrays. The entries in the total array should be the product of the corresponding values in the price and amount arrays. After all the data have been entered, display the following output:
Total Price Amount
==== ==== ======
Under each column heading display the appropriate value.
I know how to display everything using printf, how to create the actual arrays and define the array size, but I am confused on how and what loop to use and how to construct it. This is what I have managed to write up so far:
import java.util.Scanner; // Imports the Scanner class
import java.text.DecimalFormat; // Imports the DecimalFormat class
public class Prices
{
public static void main(String [] args)
{
double[] price = new double[10];
double[] amount = new double[10];
double[] total = new double[10];
// Create a new Scanner object
Scanner keyboard = new Scanner(System.in);
} //End of main method
} // End of public class
View Replies
View Related
Sep 24, 2014
Using Bluejay. Need code that prompts user to enter 5 test scores and their names. Calculate the average and display.
First initial and last name , 5 test scores, and average
View Replies
View Related
Nov 2, 2014
I want to store an image/file into oracle database using jsp.
I have written code to store data when am running in my machine it is working fine, but not working in server throwing an error saying that "The system cannot find the file specified."
I am attaching the code what am written.
View Replies
View Related
Sep 12, 2014
I have to store the name SD array and display the room and floor no. whose name is entered but i am having a problem with the logic part. The answer is coming to be wrong
import java .io.*;
class hotel
{
public static void main()throws IOException {
InputStreamReader read = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(read);
String ar[][] = new String[5][10];
[Code] ....
View Replies
View Related
Feb 2, 2014
When I add an array of action-objects (the class extends AbstractAction)
to a combo box, I do receive the action performed events, great!
But the combo box items show the long string of the action object, of course!
How to render that string in a way that only the Action.NAME appears?
I was experimenting a little, but could not make it to work:
Java Code: private class ComboRenderer2 extends BasicComboBoxRenderer {
@Override
public Component getListCellRendererComponent(JList list,
[Code]....
View Replies
View Related
Nov 12, 2014
I am trying to write a program that will generate a QR Code from an input text and also display some information about the input/output bits. So far I have created the frame and what to do next. And I'm not sure if I am on the right track since my level of programming is not that great. By the way, I am using zxing libraries from GitHub. I know, there are plenty of generators online for the QR Code, but that is not what I am looking for. As you can see on the attached image, I am more interested in the efficiency of encoding 2D data. Also, I noticed that almost all the online projects regarding 2D codes are for Android. Which is not very useful.
// QR Code Generator
package qrcode;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
[Code]....
View Replies
View Related
Apr 5, 2014
I have a college question ask me to write a class StringRevert which does the following:
-prompting user for an interger n
-creating an array of n string
-repeatedly read character string from user input and store them in the array until end of array is reached or user input -quit(quit should not saved in array)
-print the string from array in reverse order, from last enter to first enter.
-assume user always supplie correct input
This is what I've done so far but how to get it working.
import java.util.Scanner;
public class StringRevert {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("enter value of n: ");
int n1 = in.nextInt();
String[] n = new String[n1];
[Code] ....
View Replies
View Related
Oct 1, 2014
I'm playing with vectors for the first time... What I'm trying to do is to allow a user to input one or more integers and store them in a vector for manipulation later on in the program... Here's the portion of the program I'm working with:
Java Code:
package com.itse2317;
import java.util.*;
public class VectorTest
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
[code]...
My question is this: Is there any way to move from inputting integers to printing them, without entering a non-integer (for example, hitting enter)? I looked at the API for the Vector class, and either I'm not thinking about the problem the right way to be able to find an answer, or it's just not there.
View Replies
View Related
Jan 28, 2015
I am still new to Java and have an assignment that I am stuck on. I believe I got the boolean function correct, however I cannot figure out what to write in the main function. I have exhausted searching, and trying different loops, arrays, etc.
View Replies
View Related
Apr 15, 2014
I'm trying to read user input from the terminal and separate the input into separate arrays depending on if the user input is an integer, scanner, or a string. The terminal should keep asking the user for input until the user types "quit".
import java.util.*;
public class arrayScanner {
public static void main(String[] args) {
ArrayList<Integer> intList = new ArrayList<Integer>();
ArrayList<Double> doubleList = new ArrayList<Double>();
ArrayList<String> otherList = new ArrayList<String>();
[code].....
View Replies
View Related
Dec 4, 2014
Write a program to maintain a list of the high scores obtained in a game. The program should first ask the user how many scores they want to maintain and then repeatedly accept new scores from the user and should add the score to the list of high scores (in the appropriate position) if it is higher than any of the existing high scores. You must include the following functions:
-initialiseHighScores () which sets all high scores to zero.
-printHighScores() which prints the high scores in the format: “The high scores are 345, 300, 234”, for all exisiting high scores in the list (remember that sometimes it won’t be full).
-higherThan() which takes the high scores and a new score and returns whether the passed score is higher than any of those in the high score list.
-insertScore() which takes the current high score list and a new score and updates it by inserting the new score at the appropriate position in the list
View Replies
View Related
Oct 15, 2014
I am writing a program that grab user input number which represent beats per minute separated by commas. It then parses the numbers and reorders them from smallest to largest and then outputs the average, medium, maximum and minimum number all in separate lines. I am having trouble getting the array to sort the input from smallest to largest. It is currently only working for 3 numbers inputted. Anything more will not reorder it.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package heartrate;
import java.util.Scanner;
import java.util.Arrays;
[Code] ....
View Replies
View Related
Oct 12, 2014
I am new to using arrays. I need to collect user input for book title, author, and # of pages... store that in an array... and then I'm going to need to be able to sort that array. The dialog boxes come up prompting the user for 5 sets of title, author, and # of pages, but when I try to display that information, it isn't working. I am assuming this means that it's not storing the information correctly... so I want to get this corrected before I even try to sort??
import javax.swing.*;
import java.util.*;
class LibraryBookSort
{
public static void main(String[] args)
{
LibraryBook[] someBooks = new LibraryBook[5];
[Code] ....
View Replies
View Related