Identical Array Program

Oct 7, 2014

I am trying to write a program where I input numbers and if both arrays contain the same numbers it prints out identical. If not it prints out not identical. The issue I am having is that it says I am missing return statement at the very end of my program (the last bracket).

I added the else at the very end before the return true and this was the error that occurred. However is I remove the else all it says is lists are not identical even if they are?

import java.util.*;
import java.util.Scanner;
import java.util.Arrays;
public class Tester {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);

[Code] ....

View Replies


ADVERTISEMENT

Sorting Array First By Name Then If They Are Identical By ID

May 8, 2014

I'm in the process of doing a module grade book project and I have a working program, however I have to sort the array of students created first of all by name and then if they are identical, by student ID. I've looked at the compareTo method on several websites and I still don't know how to implement it in my code.

My main is as follows;

public class CommandLineTest {
public static void main(String[] args){
String moduleTitle=Input.getString("Enter module title: ");
double cwPercentage=Input.getDouble("Enter coursework percentage: ");
double examPercentage=Input.getDouble("Enter exam percentage: ");

[Code] .....

View Replies View Related

Two Classes With Identical Constructors?

Jun 3, 2014

Is it possible to combine two classes that I have defined to contain some of the same elements so that NetBeans stops giving me errors? I don't want to get rid of any necessary code, and if both classes are necessary, should I just rename one of them? One class is an ArrayList that I am using to write the information for employees entered to a text file "employee.txt." I also want users to be able to call on this information via employeeID in order to display employee information. The code is the following:

public ArrayList<Employee> getEmployees() {
// if the employees file has already been read, don't read it again
if (employees != null)
return employees;
employees = new ArrayList<>();
if (Files.exists(employeesPath)) // prevent the FileNotFoundException {

[code]....

The other class is a getEmployee class that I previously defined before attempting to read the information from the text file and display it in the console. It is as follows:

private void getEmployees() {
try {
// if the file doesn't exists, create it
if (!Files.exists(employeesPath))
Files.createFile(employeesPath);
BufferedReader in =
new BufferedReader(
new FileReader(employeesFile));

[code]....

View Replies View Related

Methods Of StringBuffer And StringBuilder Are Identical

Apr 4, 2014

" In terms of methods supported by the classes, the methods of StringBuffer and StringBuilder are identical. They only differ in whether the methods are synchronized or not. " - Oracle Certified Associate Java SE7 Programmer Study Guide

What does synchronized mean in this context?

View Replies View Related

Change Program Below To Array

Feb 14, 2014

I need to change the program below to an "array"....

public class RecursiveFibonacci {
public int fibonacci(int n) {
int result;
if (n == 1 || n == 2)
result = 1;
else {
int n1 = fibonacci(n-1);
int n2 = fibonacci(n-2);
 
[code]....

View Replies View Related

Program That Use Array To Store 10 Numbers

Oct 16, 2014

i'm trying to write a program that uses an array to store 10 numbers. The numbers should be randomly generated ( Math.random() ), and they should be between 1 and 100 ( 1 and 100 inclusive ). The program should produce an output like the one below:

Element 1 = 23 ( Odd )
Element 2 = 15 ( Odd )
Element 3 = 32 ( Even )
Element 4 - 10 ( Even )
Element 5 - 99 ( Odd )
Element 6 - 1 ( Odd )

[Code]...

I have written code for this but its only showing me 0's after first number can you check whats wrong with my code. my code is.

class even/odd{
public static void main(String[]args){
int y=0;
int z=0;
int[] array= new int[11];
for(int x=1; x <array.length ; x++){
array[x]= (int) (Math.random()* 100);
 
[Code]...

View Replies View Related

Array Program Printing Error

Apr 25, 2014

Ok, so the program we are supposed to do is to create implement a employee class then create a main tester class that can accept user inputs for 5 employee names, salaries, and performance rating. After that, we have to input code to calculate a provided raise amount, then print out the array with the updated raises. I have completed the program with no syntax errors, but it doesn't do anything. not even a screen comes up on my end to accept user inputs. I know its something basic, but what am i missing

Employee class
public class Employee
{
private String employeeName;
private int salary;
private int performanceRating;

[Code] ....

View Replies View Related

Array In Space Invaders Program

Mar 7, 2015

Java Code:

public synchronized boolean isHit (FilledRect missile) {
for (int col = 0; col < aliens[0].length; col++) {
for (int row = 0; row < aliens.length; row++) {
if (aliens[row][col]!= null && aliens[row][col].overlaps (missile)) {
aliens[row][col] = null;
return true;
}
return false;
}
}
} mh_sh_highlight_all('java');

And I get an error saying that it cannot find symbol method overlaps. So is there something wrong that I am doing?

View Replies View Related

Program Should Print Array As Output

Jul 11, 2014

Write a program to create an integer array of size 20. Then, the program should generate and insert random integers between 1 and 5, inclusive into the array. Next, the program should print the array as output.

A tremor is defined as a point of movement to and fro. To simulate it, the program will generate a random number between 0 and 19, which represents the location in the array (i.e. index number). Then, the 3 numbers to the left and right of this location should be reset to the value 0. If there isn't 3 numbers to the left and right you may assume a lesser number depending on the boundaries of the array.

Then, the final array should be printed as output. There is no user input for this program.Your program must include, at least, the following methods:

-insertNumbers, which will take as input one integer array and store the random numbers in it.
-createTremor, which will generate the random number as the location and return it.

A sample run of the program is shown below:

Sample output #1:
Array:1 2 2 3 1 5 4 2 3 4 4 2 1 1 3 2 1 4 3 2 1
Random position: 5
Final Array:1 2 0 0 0 5 0 0 0 4 4 2 1 1 3 2 1 4 3 2 1

View Replies View Related

Program That Prints Repeated Integer In Array

Apr 8, 2015

So I'm trying to write a program that prints out the "most-repeated integer" in an Array.

For example: if an array contains {1,2,2,3} It would print out 2 as the result.This is what I got so far and according to my knowledge I think I'm correct but for some reason it doesn't work.. Please give me some inputs.

public class MostInt{
public MostInt (){
int[] array = {0};
for(int i = 0;i>array.length;i++){
if(i==i++){
System.out.println(i);

[Code]...

View Replies View Related

Create A Program That Asks User For Array

Mar 3, 2014

i need to create a program that asks the user for an array and then asks the user to fill in the slots of the array but i have to do it in a method

View Replies View Related

Program That Find Minimum Value In Array Of Integers

Feb 3, 2014

I'm required to create a program that finds the minimum value in an Array of integers.

Here is my approach :

public class Person {
public static void main(String [ ] args){
int theArray[]=new int [10];
int result = 0;
for (int i:theArray){
if (i < Integer.MAX_VALUE)

[Code]...

I can't really progress from this position. I keep getting told to change the return type to int on main method, then when i do it says change it to void..

View Replies View Related

Working On A Program That Creates Array From A File

Feb 19, 2015

Working on a program that creates an array from a file, organizes it in various ways, and then prints the results. Right now I'm specifically having trouble with the printAry() method - when I try to run it, I receive a NullPointerException for the active line in printAry() (EDIT: line 102). Not sure which sections are important to this, so I will include the client class and most of the service. I realize that the amount of documentation I included is not necessary, but it is required for the class.

class Lab3StudentAryService
{
private int count;
private Lab3StudentData [] studentAry = new Lab3StudentData[50];

/*
@param: none
@return: none
reads file and converts to array.
*/
public void fillAry() //constructor
{
Scanner scan = new Scanner(System.in);

[code]....

View Replies View Related

Order Of Numbers - Reverse Array Program

Apr 23, 2015

import java.util.Scanner;

public class ReverseOrder {
public static Scanner input = new Scanner(System.in);
public static void main(String[] args){
int[] numbers;
double[] reverse;

numbers = readArray();
reverse = reverseOrder(numbers);

[Code] ....

I have to write a program that takes an order of numbers and print the reverse order of those numbers.

the out put i receive is:

How many numbers do you want to enter?
4
Please enter 4 integers separated by a space:
1 2 3 4
Your numbers in reverse order are:[D@1f96302

View Replies View Related

Write A Program To Create Integer Array Of Size 20

Aug 2, 2014

Write a program to create an integer array of size 20. Then, the program should generate and insert random integers between 1 and 5, inclusive into the array. Next, the program should print the array as output.

A tremor is defined as a point of movement to and fro. To simulate it, the program will generate a random number between 0 and 19, which represents the location in the array (i.e. index number). Then, the 3 numbers to the left and right of this location should be reset to the value 0. If there isn't 3 numbers to the left and right you may assume a lesser number depending on the boundaries of the array.

Then, the final array should be printed as output. There is no user input for this program.Your program must include, at least, the following methods:

-insertNumbers, which will take as input one integer array and store the random numbers in it.
-createTremor, which will generate the random number as the location and return it.

A sample run of the program is shown below:

Sample output #1:
Array:1 2 2 3 1 5 4 2 3 4 4 2 1 1 3 2 1 4 3 2 1
Random position: 5
Final Array:1 2 0 0 0 5 0 0 0 4 4 2 1 1 3 2 1 4 3 2 1

View Replies View Related

Program To Initialize And Display Variable Size Array

Aug 18, 2014

Write a program to initialize and display variable size array.

View Replies View Related

Java Program That Reads Array From Text File

Mar 19, 2015

I was wondering if it's possible to do this: I want to build a java program that reads a java array from a text file.

Then I want to read it, and output it in a different format.

The reading and out is easy - as text.

But how can I incorporate the read text in to a java valid array in my program, which I can use?

Is this even possible?

View Replies View Related

Writing A Program That Searches Array Using Binary Search

Jul 10, 2014

I'm (failing at) writing a program that searches an array using binary search, but I can't get it to work.

My code so far is this:

Java Code:

package sorting;

import java.lang.*;
import java.util.*;
public class sorteh {
public static void main(String [] args){
int[] array=new int [20]; //creates new array
for (int x=0;x<array.length;x++){ //populates array
array[x]=x*3+1;

[code]...

I copied what a website did for the sorting part, but if I have low=0 and high=19, wouldn't mid not be an int?

View Replies View Related

Console Calculator Program - How To Split Array Of Strings

Apr 22, 2015

I'm writing a command line application of a calculator in Java. I need to be able to (as per program requirements) split the array of strings (6+3) into an array of strings? How would that be done? I know you can use the split method, but I am not really sure how that wold work to perform math with them?

On a side note: for this application, how could you make the program accept a variety of different lengths of strings to perform math with them?

View Replies View Related

Inventory Program - Displaying Information (Input From Array)

Sep 13, 2014

I'm working a an assignment for my IT/215 class and I'm having a little trouble with my arrays. My code compiles just fine but when it comes to displaying the information I've input into my array it doesn't seem to want to and I'm not sure what I'm doing wrong here. On line 136 originally I had [DVDs [count] = count+1]] but it wouldn't compile. I then put line 136 to [ DVDs[count] = new Inventory();] and I think that's were my issue is but I'm not sure....

// Purpose:the purpose of this software is to display inputs as wells as the stocks and price of inputs.

class Inventory
{
private double ItemNumber; //to store Item number
private String ItemName; //to store Item name
private double UnitsInStock; //to store number of units in stock
private double UnitPrice; //to store Unit price
private double InventoryValue; //to store Inventory value
private double TotalInventory; //to store Total Inventory value

[Code] .....

View Replies View Related

Personality Test Program Not Changing Array Values

Apr 1, 2014

I'm making a program for school that reads a text file with answers to a personality test and prints the temperament to an output file. Problem is, it sets the temperament for the first person to INFJ and then prints INFJ for the rest of the people too. My code is below, and the input file 'personality.txt' goes like this:

Betty Boop
BABAAAABAAAAAAABAAAABBAAAAAABAAAABABAABAAABABABAABAAAAAABAAAAAABAAAAAA
Snoopy
AABBAABBBBBABABAAAAABABBAABBAAAABBBAAABAABAABABAAAABAABBBBAAABBAABABBB
Bugs Bunny

[Code] ....

This is my Code :

public static void main(String[] args) throws FileNotFoundException {
welcome();
Scanner input = new Scanner(new File("personality.txt"));
PrintStream out = new PrintStream(new File("output.txt"));
int[][] outcome = new int[4][2];
double[] percent = new double[4];

[Code] .....

View Replies View Related

Program That Allows User To Enter Up To 10 Integer Grades Into Array

Apr 30, 2015

package question.pkg3;
import java.util.Scanner;
public class Question3 {
public static void main(String[] args) {
// TODO code application logic here
Scanner Luka=new Scanner(System.in);
double sum=0;double count=0;
int[] a=new int[10];

[code]....

I'm required to write a program that allows the user to enter up to 10 integer grades into an array. Stop the loop by typing in ‐1. Your main method should call an Average method that returns the average of the grades.I There's something wrong with my program , the count always stays 0 and the sum is always 1 less than the actual sum.Sample input and output :

Enter grade 1: 8
Enter grade 2: 9
Enter grade 3: 10
Enter grade 4: 5
Enter grade 5: 8
Enter grade 6: 9
Enter grade 7: -1
output

Average grade is 8.1666666667On line 13 I had count=count+1 ;

View Replies View Related

Transferring Coordinates From Design Program To Array In Java?

Mar 6, 2015

The idea I'd like to present, concerns the correction of "designer" drawings - those done by the design consultants - against "site/construction" drawings - them being used on site by the workers to build the project itself.

This is normally a laborious process, involving being sat at a desk with two large folders, checking each detail and measurement against the design drawing.What I'd like to present is an idea, where the co-ordinates of the design or "mother" drawing, are transferred into a usable Java program, and they could be then used to ensure correct dimensions have been applied by the the sub-contractors in their "construction" drawings.Like I said, this can normally be a process of days for a site engineer to check - process known as "QA, quality assurance".

Basically, I just need to make a presentation of having a genuine interest in Software Design and Development. It could be applied in a range of areas in terms of construction site application - checking drawings, writing up work orders, dig orders etc - but the principle of having the co-ordinates of the mother or "design" drawing scanned into an array in Java as a means to output those site drawings/orders etc, applies to each potential application.

So - in short - and not looking for crystal clear detail, just general pointers - what programs or methods could transfer a plethora of co-ordinates from a design program like Auto-Cad, to a Java program, where I assume I would then be using a program containing a complex series of loops to ensure the correctness of the derived "construction" drawings; derived from the "mother" or designer drawings, that is.

View Replies View Related

Program To Store Total Rainfall For Each Of 12 Months Into Array Of Doubles

Oct 26, 2014

"Create a project called RainFall and a class nameD RainFall. Write a program that stores the total rainfall for each of 12 months into an array of doubles. The program should display total rainfall for the year, the average monthly rainfall, the month with the most rain and the month with the least rain. When outputting the month with the most and least rain, output the name of the month. This is what I have so far.

Scanner keyboard = new Scanner(System.in);
double averageMonthly;
double mostRain;
double leastRain;
int months;
double monthlyRain = 0;
double totalRain = 0;

[Code] ....

View Replies View Related

Create Program That Draws Random Numbers And Stores Them In Array

Oct 1, 2014

Is my code right for this pseudocode:

<Declaration of the array for storing random integers and other necessary variables and / or constants. >

private int numbers;
private int max;
private int[] integer;
private Random generator;
public integer ( int n, int m )

[code]....

I need to create a program that draws random numbers and stores them in an array. How many numbers to be drawn is dependent on the array length, which is a parameter in the class constructor. (The entire array to be filled!) The program shall, however, just save the figures are not drawn already. (Ie, the array must contain only one instance of each numeral.) All figures drawn should be in the range of 100 to 1000, both limits included. These limits are defined as named constants. When all the numbers are generated and stored in the array, the program should find the largest, smallest and average value of the numbers in the array. In addition, it should find the value closest gjennomnstittetsverdien.

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







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