Create A Method Called MirrorImage Which Takes Two Integer Arrays As Input Parameters

Jan 8, 2009

Create a method called mirrorImage, which takes two integer arrays as input parameters. You may assume that the two actual parameters have the same length. Your method should return true if the arrays are the reverse of each other. Otherwise mirrorImage should return false.

Examples:

data1:{1,2,3}
data2:{3,2,1}
==> true

[code].....

I'm pointing a place outside of the array or something

runtime error (line 8, column 0): java.lang.ArrayIndexOutOfBoundsException: 10

-> array.ArrayQuestions.mirrorImage()

View Replies


ADVERTISEMENT

Write A Method Called AddToOverThirty Which Takes Array Nums3 As A Parameter

Apr 22, 2014

i have to "Write a method called addToOverThirty which takes the array nums3 as a parameter. It adds 1 to all numbers that have a value greater than 30 in the array.

Add a call to the addToOverThirty method, then display a message telling what the output is followed by the results For example:The nums3 array after adding 1 to all numbers greater than 30 is10 6 15 and so on (check with the values you assigned to nums3)"its pointless because we were told not to make the array have a number over 30.

import java.lang.*;
import java.util.*;
public class LastProject
public static void main(String[] args) {
int nums1[] = new int[15];
int nums2[] = new int[15];
int nums3[] = {5,2,15,8,26,22,1,29,4,23,30,11,19,6,24};

[code]....

View Replies View Related

Create A Recursion Method That Takes ONLY ARRAY As A Parameter

Mar 9, 2015

so i have this question where it wants me to create a recursion method that takes ONLY THE ARRAY as a parameter, and without using loops or static variables inside the method, and then the method returns the smallest value in that array. However, i tried making the simple if statements where i compare the first element of the array with the second element using the length of the array and decreasing it to get the next elements and compare it again by calling the recursion method, but the problem is when i call the method again, the length does not decrease, even if i store it in a variable, the variable will initialize itself again, and the length wont change.

View Replies View Related

Create Class Called Factorial Algorithm Which Will Compute / Print Factorial Of Integer Number On Screen

Dec 27, 2014

1)A factorial of a number X is equal to X*(X-1)*(X-2)*...*1.For example,3! is equal 3*2*1=6.Create a class called Factorial Algorithm which will compute and print the factorial of an integer number on the screen

2)Write a Java program to accept eight integers and a search element from the user and display whether the element is found or not.(Hint:use bubble sorting and binary search)

View Replies View Related

JSP :: Why Init Parameters Were Not Fetched When Its Directly Called

Apr 9, 2014

web.xml

<web-app>
<servlet>
<servlet-name>pqr</servlet-name>
<jsp-file>/index.jsp</jsp-file>
<init-param>
<param-name>email</param-name>

[code]....

I dint understand why the init parameters were not fetched when i directly called the JSP??

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

Lexicographic Ordering - When Input String Values / No Output Takes Place

Jan 28, 2015

I have a assignment to do some Lexigraphic ordering. I have figured how to get the majority of this done, however, when I input my string values. No output takes place? :s

import java.util.Scanner;
public class Lab03c {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner lexi = new Scanner (System.in);
String s1,s2;

[Code] ....

View Replies View Related

Create A Program Called MyStack

Apr 15, 2014

We have to create a program called MyStack.In Push: Add one element at the end of the buffer.In Pull: Remove one element from the end of the buffer. In isEmpty: Should check if the list is empty or not and return the result as a boolean variable.

I am totally confused, I wrote the buffer and the array, but how do i add an remove element from the buffer?How do i add an element? What Statement do i Use?

Java Code: public class MyStack<T> implements Stack<T> {
private final T[] ringbuffer;
int index = 0;
int last;

[code]...

View Replies View Related

Method Call That Takes Large Of Two Absolute Values

Oct 6, 2014

Write a method called largerAbsVal that takes two integers as parameters and returns the larger of the two absolute values. A call of largerAbsVal(11, 2) would return 11, and a call of largerAbsVal(4, -5) would return 5.

I have tried this code using methods in the Math Class but I am getting an error in Practice-it that says

Line 4
Your method's return type is void, which means that it does not return a value. But your code is trying to return a value. This is not allowed.

cannot return a value from method whose result type is void
return Math.max(Math.abs(Num1), Math.abs(Num2));

Here is my code. What I am doing wrong?

public static void largerAbsVal (int Num1, int Num2)

return Math.max(Math.abs(Num1), Math.abs(Num2));
}

View Replies View Related

Create A Class Called Dice To Represent SINGLE Cube

Apr 15, 2014

I need to work on this "Dice" program. I've done it twice already. I've also been pouring over examples on here and elsewhere online, but none of them exactly match what I'm doing, as they all say "Pair of Dice".Mine says: "Create a class called Dice to represent a SINGLE cube". It should have a method called roll() that randomly selects a number from 1-6 for the value of the dice."

It has to use java.util.random, not math.java, and it has to have numberShowing:int, roll():int, and main() all in it.The last part reads "Create a test main method for the Dice class that creates a dice and rolls it many times. Can you keep track of how many times a number comes up? Describe how or implement it in the program." I have started at this computer for hours, and read as much info as I can.

View Replies View Related

Polymorphism - Which Method Gets Called

Jan 29, 2015

While studying polymorphism , i have some doubts that i am unable to clarify ..... Here they are :

Suppose our inheritance ladder be :
C1 <- C2 <- C3 <-....... <- C100
where C1 is most general (superclass) and C100 is most specific class .
Now , if i write java code in my main() :

C21 Obj = new C100();
Obj.someMethod();

So, what will happen in scenarios as given below :

Scenario - 1) If someMethod() is only defined in C1 ? How will compiler search for this someMethod() ?Will it be executed ?
Scenario - 2) If that someMethod() is static and only defined in C1 , then how will it be searched and executed ?
Scenario - 3) If someMethod() is only present in C100 , then what will happen ?

View Replies View Related

Generating Method To Be Called

Jun 25, 2014

I want to call getter method from method based on parameter send to this method e.g

Java Code:

void myCrazyMethod(MyDto dto, String prop){
System.out.println("Value of " + prop + ": " + dto.get{Prop}()");
} mh_sh_highlight_all('java');

View Replies View Related

Method Called At Start?

Nov 24, 2014

So, I have a gameOver() method that should when oval goes out of bounds abort game but, as soon as I start the game it runs the gameOver method. I've been looking over it for a while trying different things. I think what stood out to me is removing the abort sequence the game runs mostly as it should after, popup is closed and that if I replace game.gameOver(); with ya = -1 the ball bounces off the wall.

gameOver()
public void gameOver(){
JOptionPane.showMessageDialog(this, "Game Over", "Game Over", JOptionPane.YES_NO_OPTION);
System.exit(ABORT);

[Code] ....

View Replies View Related

Method Not Called Within Thread?

Oct 23, 2014

have written a new class that contains a thread.

From within that thread I try to call a method from within the same class the contain the thread. This method is not being called. I have confirmed that that section of code is being executed in the thread.

If you look at the following code, the thread being run is called MainThread ln 114, and the method it calls that is not being executed is called onprogressTime() ln 105;

package com.example.scott.coloursquares;
import android.content.Context;
import android.graphics.BitmapFactory;

[Code]....

View Replies View Related

Invoking Non-Existent Method - Matching Parameters To Method

Oct 17, 2014

Java-code, When i compile the java doc. I get output;

Perceptron.java:12: learn(Instance[],int,int) in Perceptron cannot be applied to (Instance[],int)
PerceptronModel model = learn(train_data,5);
^
1 error

And here is the code

import java.io.*;
public class Perceptron {
public static void main(String[] args) throws IOException {
DataReader reader = new DataReader();
reader.init(args);

[Code] ....

View Replies View Related

Can't Seem To Get Value For Integer 1 And Integer 2 To Pass With SetValue Method

Aug 10, 2014

public class MyInteger {
private int value;
public MyInteger(int number){
value = number;
System.out.println("Constructor created with value of " + value);

[code]....

I can't seem to get the value for integer1 and integer2 to pass with the setValue method. I get a runtime error stating the I need to have an int value for these two integers.

View Replies View Related

Public Method That Takes Array Of Type Object To Load Strings Into Linked List

Oct 13, 2014

I am having a little trouble with a part of my Java assignment that needs to have linked lists in it.

I need to write a public method that takes an array of type object to load strings into a linked list.

View Replies View Related

Recursive Method Called RangeSum

Oct 3, 2014

I'm trying to understand the concept behind this recursive method called rangeSum. This method sums a range of array elements with recursion. I tried summing the elements of 2 through 5, and I tried writing down what actually happens when java executes the program, but what I get when I try to figure it out by paper is different from what netbeans gives me. Here is a snapshot of my scratch work as well as my source code. Netbeans gives me "The sum of elements 2 through 5 is 18" when I try running it but it I get 12 when I do the recursion on paper. I know that the source code is correct because it's out of the book but what am I doing wrong when I try figuring it out by hand?

XML Code:

package recursivecall;
import java.util.Scanner;
/**
* Author: <<Conrado Sanchez>> Date: Task:
*/
public class RecursiveCall {

public static void main(String[] args) {

[code]....

View Replies View Related

Write A Class Called Coin Which Will Be Used By A Program Called CountFlips

May 1, 2014

i am trying to write a coin program:Write a class called Coin which will be used by a program called CountFlips.

1. The class, is an object created from this program. It is composed of data values and methods. It should contain a main method and should output the number of flips done (an integer that will be read from the user), the number of heads and tails that occur.

2. The CountFlip class will flip a coin multiple times and counts the number of ‘heads’ and ‘tails’ that result. This class should have a method called flip() of type void; a method called isHead() of type Boolean and a toString() method that will return the current face of the coin as a string.

So i created 2 classes, one called Coin.java & the other CountFlips.java,

PHP Code: package test;
public class Coin {
private final int heads = 0;
private final int tails = 1;
private int facetype;
private int flips;

[code]....

View Replies View Related

Program That Takes User Odd Number And Print Prime Numbers Lower Than User Input

Nov 4, 2014

I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.

public class PrimeNumber
{
Scanner scan = new Scanner(System.in);
int userNum;
String neg;

public void getUserNum()

[code]...

View Replies View Related

Create A Constructor With Eight Parameters Containing Both String And Integers

Feb 28, 2015

I have to create a constructor with eight parameters containing both string and integers.the variables were supposed to be entered by user. but when I try to create an object of the class the IDE post error messages about the constructor.

public class hfiledriver {
//the class name is hfile
//after the main method I try creating an object of the class
//after prompting the user to enter the data
hfile hfile= new hfile(firstname, lastname, gender, age, weight, height);
}

View Replies View Related

Create Constructor With Parameters And Methods In Same Class?

Feb 28, 2014

The one problem in my book was to create a constructor for different shirt features, which I did and ran successfully. Out of curiosity, I also added other methods to see if it would run if the parameters were different from the constructor. It keeps giving me a constructor error. So, my question is, am I able to create a class that uses a constructor with parameters and other methods without errors? I'm guessing there's no reason to since it would be wasted space since the constructor could do it but was just curious if it's possible.

Is everything from the constructor down (in the class) and Shirt.oneShirt (in the main) just a waste of time?

Here's my example:

public class Shirt//class name.
{
int collarSize;//data field.
int sleeveLength;//data field.
int pocketNumber;//data field
public final static String MATERIAL = "cotton";//final data field for material.
public Shirt(int collarSize, int sleeveLength, int pocketNumber)//start of constructor.
{

[Code]...

View Replies View Related

Using Same Input Parameters With Multiple Methods

Jul 6, 2014

I'm working on an assignment where I need to take radius and height from the user to use with the methods in class Cylinder. I have to use radius and height as input parameters in the methods that calculate: Base area, lateral area, total area, and volume. But when I use height and radius as input parameters then it just prints zeros for all calculated values. When I remove (double radius) from the method it works just fine. So my question is how can I get this to work with radius/height as input parameters? Or am I just misunderstanding will they still be input parameters even if I don't have it written as (double radius) in the method?

import java.util.Scanner;
class Cylinder{
double radius = 0.0;
double height = 0.0;
double baseArea;
double lateralArea;
double totalArea;
double volume;

[Code]...

View Replies View Related

How To Write Instance Method For Rectangle Class Called Contains

May 29, 2014

Write an instance method, contains, that has one explicit parameter of type Rectangle. The method should return true if every point of the rectangle determined by the explicit parameter is on or within the rectangle determined by the implicit parameter. It should return false otherwise.

This is what i did so far?

public boolean contains(Rectangle other) {
Rectangle intersect = Rectangle.intersection(this, other);
if ((intersect.left == this.left) && (intersect.bottom == this.bottom) && (intersect.width == this.width)
&& (intersect.height == this.height)) {
return true;
} else {
return false;
}
}

View Replies View Related

Method Parameters Stubbing

May 31, 2014

I am trying to write a simple test case for one of my web service.The main method

return object :: offersService
MainClass
public OffersService getOffers(String input1, Map input2) {
// userId, Password loaded from another properties files
String response = validateUser(String userId, String Password)

[code]...

View Replies View Related

Call To A Method Signin With Two Parameters Name And Password

Nov 21, 2014

This code had no bug until I wrote down a call to a method signin with two parameters name and password. I need to know where exactly do I write down the deifintion of this method public void signin(String name, String password).

I have tried writing this several times and each times I get an annoying syntax error asking for more curly or round brackets.. There is only one error it shows after declaring this method . So I know that I am not writing it in the correct place, Do I keep it inside the action listener or outside. Everywhere am getting error. I want to be able to call methods and define them as I was doing in Bluej all this while.

import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import javax.swing.JButton;

[Code] ....

View Replies View Related







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