I am trying to pass the values for UPPER_BOUND and LOWER_BOUND from the main method into the getValidNumber method. However, I'm not sure how to do this. The rest of the code is correct as far as I know, I just need to get the values for the bounds into the getValidNumber method. How would I do this? the notes in the main method explain what I need to do.
public static void main(String[] args) throws FileNotFoundException { Scanner kb = new Scanner (System.in); final double LOWER_BOUND = 0; final double UPPER_BOUND = 100; //Call the getValidNumber method, passing it the values LOWER_BOUND and UPPER_BOUND. //Take the returned value and store it in a variable called num. //Print out the value of num (here in the main method)
I'm supposed to write a program that reads in 20 numbers stores them into a one dimensional array and then create a method that will calculate the average of the numbers in a separate method.
I've written a for loop in the main method that will take in the numbers but now I need to know how I can pass those values to a method that will calculate the average.
public class ConstructorHomework { private static double average; //Declaring the Global Variable //This Method Calculates The Average public void avg(int x){ average = x/20;
[Code] .....
This is the main method an it contains the for loop that will take in 20 numbers
public static void main(String[] args) { Scanner input = new Scanner(System.in); final int size = 20; double[] array = new double[size]; for (int i = 0; i < array.length; i++){ array[i] = input.nextDouble(); } //
Here I was trying to create and object and use it to pass value to the method
ConstructorHomework a = new ConstructorHomework(); a.avg(); //Problem is that I don't know what to put in the brackets a.showNum(); } }
i have to use a if loop. I just started using methods and loops..You have been hired as a software developer for Canada’s customs - Toronto Pearson International Airport. Your job is to develop part of the Canada Passport System. The Database Administrator has forwarded to you the database for all the Canadians. For simplicity, assume you only have five records (i.e., only five people on file). These fixed records are the following:
First name, Last name, SIN, Last Date of Entry to Canada, Number of Entries Mike beee 4567 12-12-1999 7 Jessie weree 4444 07-07-2007 1 Liza veee 2121 05-05-2013 2 Zico qeeee 2444 Never left the country 0
the two dimensional array stores all the values. In addition, all these values should be of type String.The Canadian officer can always see the following four choices:
1) Show custom’s database, 2)Update custom’s database, 3) A summary of a passenger’s record, and 4) Exit.
Choice 1 : always allows the officer to see all the database records (i.e., the five records). Each of these records consists of the following: First Name, Last Name, SIN, Last Date of Entry to Canada, and the Number of Entries (i.e., see the above stored values).
Choice 2 : allows the officer to update the database whenever one of the five Canadian passengers arrives. Once the officer chooses this option, the system will ask him/her for the SIN of the passenger. Then the system will ask for today’s date (i.e., the recent entry date). The system will then reflect those changes on the console screen and the number of entries will be increased by one.
Choice 3: summarizes the record for one passenger where his/her first and last names and last date of entry to Canada will be shown. The last date of entry should only have the last four digits (i.e., only the year). To extract those digits, you should use the String’s method(s). However,before a record is summarized, the records of all Canadians should be shown on the screen in order to allow the officer to choose among those records. Choice 4 allows the officer to exit from the system completely; otherwise the list of choices should be always shown on his/her monitor.This is the code i have so far.
import java.util.Scanner; public class QuestionFive{ public static void main(String[] args) {
double passportInput; Scanner sc = new Scanner(System.in); // public static int generalList() // to show the list of choices and return the chosen option // // public static void updateRecords(int recordSize, String[][] passportDataBase) //to update the records //
My assignment is to essentially update a calculator program that uses strings, and methods, to include arrays. How to create and call an array that the user defines the size of and then inputs the numbers to fill the array. Here's the example my prof gave us of what the output should look like:
Menu 1. Add 2. Subtract 3. Multiply 4. Divide 5. Dot product 6. Generate random array 7. Quit
What would you like to do? 1
How many values are in the arrays? 3
Enter the values in the first array, separated by spaces: 2 4 6
Enter the values in the second array, separated by spaces: 1 3 5
The result is [3.0, 7.0, 11.0]
How to create an array that would allow the user to define the size of the array and then inputs the values for the array? I'm completely lost. I never should have taken java as an online class.
I am trying to pass an object of type Product p to my editProduct method, however trying to call p.getName(); doesn't work and throws a NullPointerException. The same kind of thing works for my displayRecord method (in a different class) and I can call .getName() on Product p, also passed as an argument to that method. Below is my editProduct class. The NullPointerExcepion is being thrown at line 61 (i.e., nameField.setText(p.getName());).
I don't know if I explained right, so here's a line thing of how the classes relate:
And as a side note: adding the line p = new Product(); fixes it and successfully runs the class (including the Save and Quit parts) but obviously I want it to specifically refer to the Product I pass to the method.
I'm asking a question because I don't understand how Product p could possibly be null, because the argument is passed through my DisplayRecord class, which also takes a Product p argument and works. In that class, I have declared Product prod = p; and prod is what I am passing to editProduct.
I am having an array of strings and i want to find out whether these strings contained in the array contain a similar character or not.For example i am having following strings in the array of string:
aadafbd dsfgdfbvc sdfgyub fhjgbjhjd
my program should provide following result: 3 because i have 3 characters which are similar in all the strings of the array(f,b,d).
I can sort strings in a collection by uppercase and then lowercase though I was wondering if there is any way of doing it in reverse, sorting by lowercase then by uppercase.
I am having a problem passing an int value from one class to the other. The gist of the objective of this program is to compute a local sum at each client, and then once the local sums are computed.. to compute the overall sum from all the clients. My problem is that I'm having trouble figuring out how to pass each sum from each individual client in the class multicastSenderReceiver to the readThread class. I keep getting an error.
I feel that I have to be able to pass the sum value from each client generated in multicastSenderReceiver to the other class, because that is the only way I'll accurately be able to sum up all the values..
I'm using Java in BlueJ where I'm trying to write a class to store cycling club membership details in a map. I'm trying to pass a map as a parameter to a function that will iterate over the map and print out the member details. My code is:
public class CtcMembers { //instance variables private Map<String, Set<String>> memberMap; /** * Constructor for objects of class CtcMembers
[Code] ....
When I execute the following in the OU workspace:
CtcMembers c = new CtcMembers(); c.addCyclists();
I can see a map populated with the expected details.
When I execute the following in the OU workspace:
c.printMap(c.getMap());
I get the following error:
java.lang.ClassCastException: java.util.HashSet cannot be cast to java.lang.String in CtcMembers.printMap(CtcMembers.java:81) in (OUWorkspace:1)
I wasn't aware I was trying to cast anything so this has got me baffled.
This is my first time working with C++ and I have put together this program and came up with two errors and I am unsure what it is wanting me to do. The errors I got are:
1>c:usersownerdocumentsvisual studio 2010projectsweek5week5passing_by_value.cpp(30): error C2064: term does not evaluate to a function taking 1 arguments 1>c:usersownerdocumentsvisual studio 2010projectsweek5week5passing_by_value.cpp(38): error C2064: term does not evaluate to a function taking 1 arguments
#include<iostream> using std::cin; using std::cout; using std::endl; //initialize arrays int incr10(int* numa,int* numb);
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.
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());
I enter a value in the text box in one class and want to pass that value to another class in order to compare it and color the cell in a table. In the first class I have
I have a java application in which when starting it a map is opened and a screen is captured. The capturing is in certain time interval. I want to enable the user to change the interval for the automatic capturing the map. I placed a text box in a JPanel. I want to pass the value which was entered in it to the html page which opens a Google map. Since I am new in java programming, I found that I can do it by using applets. I made an applet, and tried to call it in the html file. But now instead of opening the map file in a browser, it opens very quickly only black window.
Here is my applet:
package cege.ui; import java.applet.Applet; import java.io.IOException; import cege.ui.GuiMain; public class AppletTInterval extends Applet { private int TimeInterval=0;
[Code] .....
And the code in the html file where I try to call the applet, i.e. to pass the value which is returned by the applet is:
<script src= <!--"https://www.java.com/js/deployJava.js"></script> <script> var attributes = { id:'AppletTInterval', code:'cege.ui.AppletTInterval', width:1, height:1} ; var parameters = { jnlp_href: 'AppletTInterval.jnlp'} ;
[Code] .....
Can I use this way to pass a value from the java class file (from the JTextField into the html file?
It just wont work... Everytime I try to pass a variable into a class it sets it to 0. What to do.
The variable should be '2', but it prints out as 0!?
Java Code: package Zoo; import java.util.Random; public class Animal { Random random = new Random(); public void Eat(){ System.out.println("The animal starts to eat.");
[Code]...
The method bash, needs the variable 'playerTwo' to be 2, to carry on. But it prints out 0.
Int the animal constructor, I passed in the variable from another class, and it prints out 2 in the constructor like it should. But outside of the constructor it is equal to 0.
I am trying to get the username and password for one class and send them to another. However I cannot send them in the constructor because a database class is getting them and I need that constructor blank. However if I do not pass the class in the constructor I get a NULL error, even better when I do pass it in I seem to get a thread lock. I do try to do my own housekeeping and close the one frame before I open a new one but it doesn't work. I will do my best to show the design of the program.
program starts Java Code: public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { // connects to database and generates a GUI new UserPromptScreen();
[code]....
I have to pass in UserPromptScreen in for it to work. This will cause me issues later with my design.
In my JSF application user starts on primary server where the session begins and then the user is redirected to a different server using sendRedirect. I want to pass some authentication token to the next server from primary server. I am trying to set session attribute as:
But this attribute is not reaching the new server. I cannot pass this auth_token as request parameter as that wont be secure. So how to get some session data to new server?
you will be making four variables (2 primitive integers and 2 Account Objects). You will be following the steps detailed below. The challenge is to understand exactly what is happening and why. Start by coding the following two methods in a java file.
Static methods: This method can be called whatever you want, however it will be public, static, and void. This method should take in four parameters: w and x which will be integers, then y and z which will be Account Objects.The first thing this method should do is to print out the four variables w, x, y, and z. This should be done in the same manner as you did in the main method. Next, change the first variable (w) to 15. After that, ted bought a new car. He now has only $20,000 in his account. Change the balance of y to be 20,000. Step three is to make a new Account Object named John, he has a balance of $10,000. Assign him to the variable z. Lastly, print all four variables again: w, x, y, and z.
I know in C++ It's possible to pass by reference but what about java?
For example, can i pass the address of a health variable into a Ninja class and then
Since Ninja inherits from an enemy class pass the health into the enemy class and within there have a function that returns that same health address and takes 5 from the health returning 95.
We are learning about how to pass objects into constructors. In our class, we made this following code:
public class InventoryItem { //fields private String description; private int units; //Add New constructor public InventoryItem(InventoryItem some_object) { description=some_object.description;
[Code] .....
As you can see the object of the same class is passed as the argument. Inside the constructor, our teacher did
some_object.description
This constructor, from my understanding, copies the description field and unit field to an object to the new object of class. Meanwhile, here is the demo class.