Stuck On Two Dimensional Arrays

Apr 13, 2014

I am having trouble grasping 2 dimensional arrays .I have a certain problem:

String[][] words = {
{"Red", "Blue", "Green"},
{"Orange", "Purple". "Yellow"}

[code]....

I ran the code and got OrangePurpleYellowRedBlueGreen.

View Replies


ADVERTISEMENT

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

Stuck Sorting Arrays

Jul 1, 2014

Write a method called isSorted that accepts an array of real numbers as a parameter and returns true if the list is in sorted (nondecreasing) order and false otherwise. For example, if arrays named list1 and list2 store {16.1, 12.3,22.2, 14.4} and {1.5, 4.3, 7.0, 19.5, 25.1, 46.2} respectively, the calls is Sorted(list1) and isSorted(list2)should return false and true respectively. Assume the array has at least one element. A one-element array is considered
to be sorted. public class thirfd {

public static void main(String[] args) {
double[] arr1 = {16.1, 12.3,22.2, 14.4};
double[] arr2 = {1.5, 0.3, 7.0, 19.5, 25.1, 46.2};
isSorted(arr2);
System.out.println(isSorted(arr2));

[code]...

View Replies View Related

Students Grading - Two Dimensional Arrays

Jun 18, 2014

I have the program bellow that grades students(based on a two dimensional array with the answers) and i need to make it display the students based on the grades/scores in ascending order . I did that in two ways (using a array and a two dimensional array) but i have a hunch it can be done much more simple then i did it (but still using array object and nothing else ) .

public class GradeExam {
/** Main method */
public static void main(String args[]) {
// Students' answers to the questions
char[][] answers = {

[code]....

My first solution creating an array with the grades for sorting :

public class C8_3 {
public static void main(String args[]) {
// Students' answers to the questions
char[][] answers = {
{'A', 'B', 'A', 'C', 'C', 'D', 'E', 'E', 'A', 'D'},
{'D', 'B', 'A', 'B', 'C', 'A', 'E', 'E', 'A', 'D'},

[code]....

View Replies View Related

2D-dimensional Arrays Of Object Types

Dec 8, 2014

I need to write a class that represents and image of RGB pixels. This class uses a two-dimensional array of object type that represents R,G and B values.

When I compile the class it completes successfully. However, when I try running a "tester" class , I'm encountering errors in a few methods. I've been trying it out for 2 days now, but unsuccessfully thus far..Those method are : rotating the image by 90 degrees clockwise (and vice versa , but I just use clockwise method 3 times for that) , shifting the image sideways, and shifting the image up/down..

I've attached the whole source code for the class , and the list of errors I get when I try to run my tester. URL...

View Replies View Related

Using Two Dimensional Arrays To Make Calculations

May 10, 2014

I am having problems figuring out how to make calculations using a two dimensional array. The problem is finding the distance of a projectile given the launch velocity and angle. The equation is x = v^2*sin(2theta)/g. I understand how to implement this equation using the toRadians() and Sin() methods. What I don't understand is how to calculate the distance values with a multi dimensional array.

double [][] data = { {20, 15},
{50, 35},
{80, 45},
{100, 65},
{150, 85},
{10, 50},
{110, 8}};

My array has the velocities on the left and angles on the right. I tried using nested loops but I don't know how to access the two pieces of data at a time which I need.

View Replies View Related

Process Data And Determine Winners - Two Dimensional Arrays

Feb 4, 2015

The international Olympics Committee has asked you to write a program to process the data and determine the medal winners for the pairs figure skating. You will be given the following file: Pairs.txt

Which contains the data for each pair of skaters. The data consists of each skater's name, their country and the score from each of eight judges on the technical aspects and on the performance aspects. A typical record would be as follows:

Smith
Jones
Australia
5.0 4.9 5.1 5.2 5.0 5.1 5.2 4.8
4.3 4.7 4.8 4.9 4.6 4.8 4.9 4.5

The final score for each skater is the sum of the average of the two categories of score. Design a class to hold the above data and the final score. Read the data in from the file and calculate the final score for each pair. Sort the array of objects , and display the results on the screen in order, giving special prominence to the medal winners.

Here is my CLass:

public class Skaters {
private String name1;
private String name2;
private String country;
private double [] arrTech = new double [8];
private double [] arrArt = new double [8];
private double score;

[code]...

how do i print my 2 arrays using the file? i got the name1, name2 and counntry to print but im stuck on printing the scores that are stored in the arrays. Also, i have to print the average for each array. one is for techniques and the other one is artistic. as you can see i already wrote the code for it but im stuck in printing it.

View Replies View Related

Unable To Create A Program For Class Using Two Dimensional Arrays

Dec 6, 2014

I am trying to create a program for class the uses two dimensional arrays. I am stuck on the second step that states Use two parallel arrays. One is a two-dimensional array -- a row of this array will hold six values in this order: [0] number of hours worked, [1] hourly pay rate, [2] gross pay, [3] net pay, [4] federal withholding, and [5] state withholding.

This is what I have so far:

Java Code:

double [][] data = new double [30][6];
String [] names = new String [30];
String str = null;
String detail = null;
int n = input(data, names, inputFile); mh_sh_highlight_all('java');
(there's more but i don't believe it pertains to this question)

My question is how would I create this array. Or, is that right above? I've searched online and in my book and I just don't understand.

View Replies View Related

Java Program That Specifies Three One-dimensional Arrays Names Price / Amount And Total

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

Tic Tac Toe Game - Random Number Generator And Two Dimensional Arrays For Game Board

May 9, 2015

Im trying to make a tic tac toe game that you play against the computer using a random number generator and two dimensional arrays for the game board. Im not trying to make a GUI, the assignment is to have the board in the console, which I have done. I have run into a few problems with trying to get the computer player to correctly generate 2 integers and have those two integers be a place on the game board. Here is my code so far.

import java.util.Random;
import java.util.Scanner;
 public class TicTacToe {
 private static Scanner keyboard = new Scanner(System.in);
private static char[][] board = new char[3][3];
public static int row, col;
 
[Code] ....

View Replies View Related

Release 1 Dimensional Array From 2 Dimensional Array

Mar 13, 2014

I have a 2x2 matrix and a 2 dimensional array.Let's say, my matrix is [a b] and array is [[1, 2], [3, 4], [5, 6],[23, 11]] .I need to multiply each 1 dimensional array in above array with the matrix.For instance,

[1, 2] multiply with [a b]
[3, 4] multiply with [a b]
[5, 6] multiply with [a b]
[23, 11] multiply with [a b]

So, each 1 dimensional array in there will be multiplied with matrix [a b] (same with matrix multiplication).how to do that multiplication in java. But I confuse how to 'release' each 1 dimensional array from the first array so I can do multiplication.How to do that in java?

View Replies View Related

Got Stuck With ClassCastException

May 18, 2014

I'm doing a project in netbeans. I have to make a on-line bank with all the GUI. In the middle i got stuck with the classcastexception..

public class Banca {
public static void main(String[] args) throws IOException, ClassNotFoundException {
// dati dei clienti
Anagrafica c = new Anagrafica();

[code]...

And here's the class of the activities of an account.. I'm not posting my classes Conto( Bankaccount) & Movimento (Activity) because those two already do what they should..

View Replies View Related

While Loop Stuck

Mar 16, 2014

I'm trying to do the following and my code is putting me in a loop and not allowing me to input a valid entry after using an invalid #.I ask the user for input which contains a loop if the user doesnt use the correct information, however the loop doesnt allow the user to input if the entry fails the which statement

import javax.swing.JOptionPane; // Needed for JOptionPane class
public class LoanQualifier
{
public static void main(String[] args)
{
double salary; // Annual salary
double yearsOnJob; // Years at current job
String input; // To hold string input

// Get the user's annual salary.
input = JOptionPane.showInputDialog("Enter your " +

[code]....

View Replies View Related

For Loop - Integers Stuck At 0

Oct 6, 2014

I have this code running correctly in Eclipse all except that it seems no matter where I declare, highest, lowest, average they always seem to stay at "0". I have a feeling the location of the Initialization is not the error since I have tried moving it to inside differ loops.

Stipulations on writing this code are:

Note: You do not need to use array to save each input score for this lab. A Single loop to read in each grade, compare with the current highest grade, lowest grade, and calculate the running sum at the same time.

import java.util.Scanner;

/*Write a program that prompts the user to enter the total number of students first.
*Then ask the user to input each student’s grade and use loop statements to read in each grade.
*Check input grade to make sure 0<=grade<=100, if the user input any other number, print out warning message and ask the user to input a new grade. Display the highest score, the lowest score and the average.
*/

public class LoopStatements {
// Main Method
public static void main(String[] args) {
// Initialize
int grade = 0; // grade value

[Code] ....

View Replies View Related

Stuck On Constructor With Parameters

Mar 19, 2014

How to use a constructor with parameters where the user inputs the information? I'm doing a problem where I create a Delivery class that accepts arguments for the year, delivery number within the year, distance code (1 for short distance, 2 for long), and weight of package. The constructor is supposed to also determine the eight digit delivery number (combining the year and delivery number, like 20140054 for this year, package #54).

I know I'm not close to being done but I'm struck on the application with the constructor parameters. If I'm asking the user to input the information, does that mean I have to create a no argument constructor so it will compile? Right now it won't compile because it's asking for the parameters but I can't put them.

This is the class:

public class Delivery {
int year;
int delNum;
double weight;
int code;

[Code] .....

And the error is:

CreateDelivery.java:22: error: constructor Delivery in class Delivery cannot be applied to given types;
Delivery firstDelivery = new Delivery();
^
required: int,int,int,double
found: no arguments
reason: actual and formal argument lists differ in length
1 error

View Replies View Related

JRadio Buttons Stuck On

Sep 26, 2014

I'm writing a temperature converter for class, and I'm done but one piece that I can't wrap my head around.My input scale radiobuttons work fine, but the output scale radiobuttons don't deselect automatically. They're two different button groups and I wrote them identical save for the variable names.

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[code]....

View Replies View Related

Stuck With A Logical Error

Jan 23, 2015

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;

[code]....

Total IS those numbers. But question[10] will not cooperate with me and it's getting a bit aggravating as I can't find a logical reason for it to be doing that.how to perhaps lock the value of total and sTotal after 10 button clicks from any?

View Replies View Related

Stuck On Pyramid Program

Feb 13, 2014

I have spent some time thinking about the program, and realize I need two loops-- 1 that keeps track of bricks in a row and 1 that keeps track of the number of rows as the Pyramid rises in height. The Pyramid is supposed to be centered on the bottom of the screen. Three CONSTANTS have been required:

BRICK_WIDTH=30, BRICK_HEIGHT=12, BRICKS_IN_BASE=14.

I tried breaking the scope of things down by trying step-wise refinement. But, I got bogged down. When I tried a method where both loops were included, I got limited success. For some reason, my equation to center along the x axis seems to be doubling the number of bricks. But, the correct number of total rows of bricks was a success. Also, the Pyramid was centered on the bottom of the screen. Another frustrating failure was that the number of bricks would not decrease as the new layers were created. My thought process was instead of using a loop that counts up (i++) I would use a loop that counts down (j--) which I thought would reduce the number of brick in each row as the "y" coordinate was reduced by each count of the BRICK_HEIGHT.

This is the code that "works". Whenever I add the (j--) the results are NOT what I expect.

/*
* File: Pyramid.java
* Name:
* Section Leader:
* ------------------
* This file is the starter file for the Pyramid problem.
* It includes definitions of the constants that match the sample run in the assignment,
* but you should make sure that changing these values causes the generated display to change accordingly.
*
[code].....

View Replies View Related

Stuck In Converting Meters In Millimeters

Feb 18, 2014

here's my code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Milimetri extends JFrame {
private JPanel p1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
private JPanel p2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
private JPanel p3 = new JPanel(new FlowLayout(FlowLayout.LEFT));

[code]...

When i write a value in meters ..and press the button b1 to show me a value in milimeters..

View Replies View Related

Swing/AWT/SWT :: Stuck With A Custom TableModel?

Feb 2, 2015

I am trying to make a custom table for a DB and i am stuck.

I want only the first column to have a checkbox and others not.

Is there a better way to insert the values instead using the getValueAt ?

@Override
public Object getValueAt(int row, int col)
{
if (col == 0)

[Code].....

View Replies View Related

CompilerThread0 And CompilerThread1 Stuck - Cpu 100% All Time

Nov 4, 2013

my application (java 6 RedHat 5.3 x64 ) using clean content jar for extracting data from email messages with attachments (doc, xls, ptt ...etc) After update from CleanContent-2009.1.1.jar to CleanContent-2011.1.1.jar (and any newer version) CompilerThreads will stuck in some cases (pretty often) In that case CPU usage is 100% all time, even when all activities on application are finished.

I was able to isolate several messages and every time when I used CleanContent-2009.1.1.jar it works ok but always stuck with CleanContent-2011.1.1.jar or newer versions!

View Replies View Related

Stuck On Average Word Length

Aug 1, 2014

The goal of this code was to create a program using main method java to analysis a piece text which has been entered from a user.

They do this by entering the text into a scanner which is then analysed by the program. The analysis is to produce word frequency, for example " This is a test" produces this results:

This is a test

1 letter words: 1
2 letter words: 1
3 letter words: 0
4 letter words: 2
5 letter words: 0

The bit that I'm stuck on is producing a mean/average, My mind telling to divide

counts.length
by
str.length

But I'm not the Best at java and I've tried to implement this but all I get are errors.

Code:

import java.util.Scanner;
public class While_Loop {
public static void main (String[] args) {
while(true){

[Code] .....

View Replies View Related

Stuck On Adding Entries Method

Apr 13, 2014

I think I'm about 90% complete with this program but I'm stuck on my adding entries method. It gives me a runtime error which says:

Enter the name:
Bill
Exception in thread "main" java.lang.NullPointerException
at Phonebook.addEntry(Phonebook.java:70)
at Phonebook.main(Phonebook.java:49)

Here is my code:
/*
* This program asks the user for input for a name, phone number and notes up
* to 200 entries. It stores every contact in a file. Type 'h' for help while
* running this program.
*/
import java.util.Scanner;
import java.io.*;

[code]....

View Replies View Related

Stuck On IsBorrowed Method Implementation

Jul 19, 2014

Basically I have a class called Book. Its supposed to have a few simple methods that set the title of the book, mark it as returned or borrowed. So specifically my problem lies in the implementation of the method that decides if the book isBorrowed. I was thinking i'd use a simple if/else statement but the way i've been trying hasn't been successful. This is what i've tried so far.

public class Book {
String title;
boolean borrowed;
boolean returned;
boolean isBorrowed;
// Creates a new Book
public Book(String bookTitle) {

[Code] .....

View Replies View Related

Stuck In A Loop - Max Value Gets Reset To The Next Value In File

Mar 14, 2014

The problem i believe is that I have the max value set to the first value given out, but every time the loop repeats the Max value gets reset to the next value in the file.

Essentially the program is supposed to read a list of credit card transactions and tell the user which transaction is the highest.

Here's the list of the sample file, note that the number of transactions could change that's why i haven't tried simply passing the values to method.

Bicycle 562.90
Groceries 138.43
Hotel 612.00

import java.io.File;
import java.io.IOException;
import java.util.Scanner;
public class CreditCards {
public static void main(String[] args) throws IOException {
String fileName = "C:/Users/David/Desktop/CreditCard.txt";
File inputFile = new File(fileName);

[Code] ....

View Replies View Related

Stuck At Checking Winner And Valid Move On Tic Tac Toe

Oct 3, 2014

public class TicTacToeGame {
public static void main(String[] args) {
char [][] board = new char [3][3];
displayboard(board);
int count = 0;
boolean loop = true;

[Code] ....

I also try with check if the move is vaild but no luck with that.

View Replies View Related







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