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


ADVERTISEMENT

How To Add Multiple Parameters To ArrayList

Feb 10, 2014

For example, if I have a class called Teacher with the constructor:

public Teacher(double yearsTeaching, boolean isMale, double age)
{
this.yearsTeaching = yearsTeaching;
this.isMale = isMale;
this.age = age;
}

How would I add it to these parameters to my ArrayList in my Tester class?

List<Teacher> teachers = new ArrayList<Teacher>();

View Replies View Related

How To Map Parameters From Multiple Classes Into One Set Of Parameter

Mar 6, 2014

I have multiple Java classes that holds lots of time based parameters, e.g.: (simplified):

Java Code: class Engine {
float rpm;
boolean enabled;
int runningTime;

[code]....

Is there any simply solution to map all these parameters from my TimeRecord to one list(vector,map) of params that user can choose from and see the value in proper form (floating type, boolean type) ?

I just want that user can pick a paremter's name from list or combobox and choose parameter that he wants to see. I don't want to duplicate the data - just some kind of mapping algorithm between list of parameters names and my TimeRecord. eg. some collection class that holds all names and connections: Parameters params; fill combo/list from this class for ( String name : params ) { combo.add(name);}, then when user picks some field from combo: params.getValue( myTimeRecord, name ) return correct parameter value (just my first thought)

Later, I want to replace all floats,ints,booleans with some kind of templated class eg. Value which will hold all kinds of measurement unit with conversion support - but it's only a plan now.

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

Generic Methods Introduce Their Own Type Parameters

Apr 10, 2014

Generic methods are methods that introduce their own type parameters. This is similar to declaring a generic type, but the type parameter's scope is limited to the method where it is declared. Static and non-static generic methods are allowed, as well as generic class constructors.

1. The method is only exclusively to be used for the declared argument parameter? For example given a generic method:public static <String, Integer> boolean method(Pair<K, V> p1) {}I could only invoke the method if Pair argument parameter is <String, Integer>?

2. Or, it will return a <String, Integer> value?

View Replies View Related

Process Of Calling Methods - Adjusting Variable Without Having It Passed Through Parameters

Feb 3, 2014

eg: "Sourdough".toUpperCase();

I guess this is actually a 2-part question:

- How does this work? (nothing seems to be passed through the parameter, so how is it that the value or variable is manipulated in this fashion?)

- How would I create a method that does something similar? (ie. adjusting a variable without having it passed through the parameters)

View Replies View Related

Multiple Methods In One Class

Sep 13, 2014

Is it possible to have multiple methods in one class?And can I use the Scanner in methods other than the main method?

View Replies View Related

When To Use Multiple Main Methods

Apr 7, 2014

I am confused when it is proper to use an application with multiple entry points, or I guess an application with multiple interconnected modules. I have a network application (Netty) as well as a web application (spring). I can bundle them together, in effect tightly coupling them together, or I can modularize them to operate interdependently of each other while still working together to make the application whole.

Is there any specific reason for making an application a single entity vs multiple entities? Is it "desired" to have a self contained application (eg. One main method)?

View Replies View Related

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 View Related

Multiple Methods Which Differs Only By Return Value

Jul 13, 2014

I have a class, which communicates with database via SQL queries. But one queries don't produce any ResultSet, while other queries do. Now I'm facing situation, where I have two methods, one which executes queries with return values and other which executes queries without return values:

public ResultSet executeQueryWithReturn(String query){
try{
return executeWithReturn(query);
}catch(Exception e){
e.printStackTrace();

[Code] .....

But I see few problems here: 1) Method can return null, (I read in book Clean Code, that people should avoid return null) Another issue - boolean value breaks the rule that method should do only one thing.

Maybe there is a better option? or maybe I should forget these two issues here for readability?

View Replies View Related

Calling Multiple Methods Into Main Method

Sep 30, 2014

This current one is to calculate a planes holding pattern. I have to write a method to prompt user to enter speed in knots, then it converts it to km/hr. Another method to calc. pattern width using the speed, another method to calc. pattern length, than a main method which would call and print out the speed in knots, speed in km, pattern width and length.My current problem is on the second method. It works in that I can enter the values and it gives me the correct answers, however it's asking me to enter the speed twice, instead of just once. Anything I try just results in errors and won't compile.

import java.util.Scanner ;
//main method
public class TitleRemoved {
public static void main(String[] args) {
double airSpeedKm = airSpeedOts () ;
System.out.println("That speed is " + airSpeedKm + " km/hr.") ;

[code].....

I want my code to not only work, but be organized and easily readable as well, so I want to avoid bad habits.

View Replies View Related

Difficulties With User Defined Variable In Multiple Methods

Apr 9, 2015

I'm trying to build a program that will output what will ultimately look like a simple mario level turned on its side. As part of my output I need the user to define what mario looks like. I do this using Scanner and save the input to String mario. When I try to use that variable in another method it gives me troubles.

import java.util.Scanner;
public class Mario2

public static void mario() {
//user defines mario
String mario = ">->O";
Scanner keys = new Scanner(System.in);
System.out.println("What does mario look like?");
mario = keys.next();
System.out.println("Mario now looks like: " + mario);
 
[code]....

View Replies View Related

Multiple Of 3 Between Range Of User Input?

Sep 22, 2014

The program should output all numbers between the starting and ending number that are a multiple of the number N. Your solution must use a for-loop. Here is example output from running the program:

import java.util.Scanner;
public class MultiplyNThree {
@SuppressWarnings("resource")
public static void main(String[] args) {
Scanner userInputScanner = new Scanner(System.in);
System.out.println("Enter 1st number: ");
int start = userInputScanner.nextInt();

[Code] ....

View Replies View Related

File Input - Multiple Sets Of Data

May 5, 2014

I am trying to create a Community Theater program that has Actors, Directors, Investors, Staff etc. I should eventually be able to input the information for the people from both a file and the keyboard. I'm working on trying to take in multiple Actors from one file and adding them to an ArrayList of Actors. My code takes in only one actor right now.

I am trying to take in multiple sets of data for the same type of class but creating new instances after each set of data (16 lines). Each actor has 16 lines of data (text file included), so I was thinking that I would need perhaps a for loop but I am unsure of how and where to implement it. I am also unsure about adding these new actors to the Actor ArrayList. I'm a little shaky on the idea of creating multiple objects when it is unknown how many you need to create. Right now, I know how many Actors I need to add but it would be nice if I could learn how to expand that based on the user's needs.

My Questions:
How can I write my program to know when it is done reading 16 lines and then initialize a new Actor (will expand to other people)?(expanded below)Eventually, I plan on using my theaterObj (an instance of CommunityTheater class), what if I wanted to move the readActorFile method to that class? Would that change the way I implement anything majorly? Would it still be a static method? I ask this because I want the Actors array to be a variable in the CommunityTheater class. I would extend this to adding actors to an ArrayList in a Play class which would be in CommunityTheater as well. So, essentially a CommunityTheater has different Play(s), and each Play contains a list of Actors.

I don't exactly know where I should put a loop (should I use a loop?) to read through each line, in readActorFile or in readInFile? How should I write this loop, as in, how do tell my program what line it's reading?

for(countLine=0; countLine < 17; countLine++) or while(countLine<17)
read all the info
and then an if(?)-

if(file has a next line)-I don't really know how to code this-start over with loop of reading information?I don't know about the for loop, as I'm not sure how to "count" lines in a text file.OR I've been thinking that readInFile in the Actor class could return something(true/false?) to let the method readInActor know that it's done reading, then readInActor can check to see if there's anything else in the file, if there is- it would call the readInFile in Actor class again to read in information... and so on. But again I am unsure of how to code this.

View Replies View Related

Switch Statements And Multiple Instances Of User Input

Sep 25, 2014

Ok, so I've seen alot of things online about writing switch code, but I can't find any involving user input, let alone multiple input scanners.

The goal is I let the user put in two different integers and it will decide based on both of the integers which of the 15 possible results it will display.

I am also not allowed to use if/else statements in this program.

View Replies View Related

JSF :: Multiple Tool Tips To Be Displayed On Same Page When Click Multiple Image Links

Dec 8, 2014

I have i am trying to implement tooltip through javascript, like when we click on an image link tooltip should be displayed and it should have close button/ close image to close that tooltip.like the same way i will have multiple images on page, when ever i click on the images all tooltips should be displayed on the page when ever i want to close that then only it should close through close button on tooltip.can we do it through java script or will go for jquery.

View Replies View Related

How To Draw Multiple Graphics Inside One JPanel Using Multiple Classes

May 5, 2015

I'm very new to Java, and I am creating a program that takes multiple user input to create one face. I have a class for the eyes, nose, lips, and headshape. For some reason, my program is not drawing the graphics. ***for question purposes, I have only included my head shape class and my test class****

my "test" class:

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class FaceTest
{
public static void main(String[] args)
{
String head = JOptionPane.showInputDialog("Would you like a circle, square, rectangle shaped head?: ");

[Code] ....

View Replies View Related

JSF :: URL With Get Parameters

Aug 25, 2014

i would like from my bean to redirect after an operation is completed to the page faces/test.xhtml?id=2? Is there a way to do this?

View Replies View Related

How To Put Parameters To Object

Aug 2, 2014

So I created this line class and when I try to create Line object with parameters, I don't know how to pass the parameters properly. It has to return two points, so it should be like [(1,2),(5,12)].I tried different things likeLine l1=new Line(Point p1(1,2),Point p2(5,12)); and similar, but nothing worked.

package line;
import java.awt.Point;
public class Line {
private Point p1;
private Point p2;

[code]...

View Replies View Related

Constructor With Parameters

Jan 31, 2015

public class TestClass {
public TestClass(String k){System.out.println(k);}
public static void main(String[] args) {
try {
hello();
}
catch(Exception e){System.out.println(e);}

[Code] ....

Explain how to catch block act as constructor with parameter?

View Replies View Related

Cannot Get Parameters For If Statement Right?

Mar 1, 2015

I have this JAVA written but I can't get the parameters for the if statements right.

import java.util.Scanner;
public class myFirstJAVA {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Please enter command: ");
String text = input.nextLine();

[Code] ....

View Replies View Related

JSF :: Passing Parameters From Servlet

Sep 12, 2014

I'm trying to pass a parmeter to a jsf page from a servlet(i.e. associated with paypal adaptive api), but I keep getting the following error, even though the productType on ProductDetailsVO is a String.

INFO: WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.

sourceId=j_idt2[severity=(ERROR 2), summary=(j_idt2: '45;productType=Sport'

must be a number consisting of one or more digits.), detail=(j_idt2: '45;productType=Sport' must be a number between -2147483648 and 2147483647 Example: 9346)]

Calling JSF page contains:-

returnURL = new URL(new URL(request.getRequestURL().toString()),"pages/paypalpaymentapproved.xhtml?paypalID="+paypalID+";productType=Sport");
response.sendRedirect(returnURL.toString());

[Code] ....

View Replies View Related

Changing Superclass Parameters?

Jul 16, 2014

My understanding was I could override a method from the superclass, including with different parameters, but when I try to use super. it gives me an error the arguments have to match the superclass. But, if I do that it won't make any sense.

The first code below is the superclass. The issue I'm having is on the second code at lines 7 and 10. The ultimate goal is to make a new class where I'm able to display various packages with or without insurance.

public class Package {
double shippingWeight;
public char shippingMethod;
final char air = 'A';
final char truck = 'T';
final char mail = 'M';
double shippingCost;

[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

Using Same Parameters But Different Functions - Allowed Or Not?

Feb 12, 2014

I have made a class here that has two methods. As you guys can notice, in my two methods that I made, I have listed some arguments in there with parameters. My question is that the variables im using in first method, can they be identical on my second method? Is this ok to do?

public class StudentScore {
private int math;
private int science;
private int calc;
private int history;
private int pe;
 
[Code] .....

View Replies View Related

Formal And Actual Parameters?

Jan 11, 2014

In the following Java Code:

public static void f() {
int n = 5;
p(n, 2 * n);
}
public static void p(int a, int b) {
int x = 1;
q(x, a + b);
}
public static void q(int x, int y) {
int z = x + y;
x = 0;
...
} mh_sh_highlight_all('java');

When we write x = 0; that refers to the formal parameter int x and hence it's the formal parameter that changes value. why isn't the value of the actual parameter also changing?

View Replies View Related







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