Write A Program That Will Call A Method To Calculate Function

Dec 3, 2014

I have understood my programming class up to this point and now I have been given a lab that I can't figure out for the life of me. Here what I have to do: Write a program that will call a method (called f) to calculate the following function" f(x)=(x^2)-16...this is what the output should be:

x f(x)
1 -15
2 -12
3 -7
4 0
5 9
6 20
7 33
8 48
9 65
10 84

I guess it also has to print this output in a table even though my professor never mentioned it. Usually

public class Lab12 {
public static int f(int x)
{
return x*x-16;

[code]....

View Replies


ADVERTISEMENT

Write A Program Using Loop And Break To Calculate Value Of Pi

Oct 5, 2014

having some trouble doing this. Here are the requirements:

1)Write a program using loop and break to calculate the value of PI.
2)You can use the following equation to calculate PI. PI=4/1-4/3+4/5-4/7+4/9-4/11+4/13 etc.. The program shouldn't loop until the criteria is satisfied.
3)The criteria is the value of PI you get is very close to the “real” value (3.1415926), meaning that their difference
should be smaller than a very small numeric number, e.g., 0.0001).
4)The control structures you may need for this program are loop, if-else, and unlabeled break.
5)The output should have the format: for each iteration, it has iteration number and the corresponding value of PI until that
iteration. The last line would be the final value of PI.

Here is my code so far:

package ids;
public class IDS {
public static void main(String[] args) {
double pi = 0;
for(int i=1; i<=100000; i++){
if ((i%2)==0){
pi+=(4/(2*i-1));

[code]...

View Replies View Related

Write A Program To Calculate Telephone Charges For Four Customers

Apr 13, 2014

Write a program to calculate the telephone charges for four customers. The data for each customer consists of NAME, PREVIOUS METER READING, PRESENT METER READING. The difference between the two readings gives the number of units used by the customer for the period under consideration.

The amount due for each customer is calculated by: UNITS USED * RATE PER UNIT + RENTAL CHARGE The rate per unit and rental charge is assumed to be the same for all customers and must be input once only.

Your program must:

a. Input the rate and rental charge
b. Read the data for each customer and calculate the amount due
c. Print the information under suitable headings
d. Calculate and print the total amount due to the telephone company

************************************
java.jpg
************************************

I just need the totalX in my for loop to print the total but the total i want to print it is in the while loop

View Replies View Related

JSF :: Call Function Inside Other Function

Jun 23, 2014

I would use the return value of a function how parameter of other function..In java is:

// the call produce "YES"
SecondClassController.funcSecondClass(FirstClassController.funcFirstClass());

In my web page I need to do something like this:

[...]
<h:outputText value="#{secondClassController.funcSecondClass(#{firstClassController.funcFirstClass()})}" />
[...]
obtain:
javax.servlet.ServletException JBWEB006007: Failed to parse the expression
@Named
@SessionScoped
public class FirstClassController implements Serializable{
[...]

[code]....

View Replies View Related

Write A Small Program That Will Calculate Gain / Loss Of Sale Of Stock

Jan 24, 2014

I am trying to write a small program that will calculate the gain and/or loss of the sale of stock. The program will ask the user for the number of shares, the purchase price and the selling price. I am pretty sure that the errors is coming from my calculations in the program.

import java.util.Scanner;
public class investmentCalculator {
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
//User input for number of shares
System.out.print("Enter the number of shares: ");
double shares = input.nextDouble();
 
[code]....

View Replies View Related

MD5 Function Call

Jan 23, 2014

my first assignment is to convert a md5 string to password of the user, the MD5 function is available, i just need to call it and print the result. Here is my code. I can't call the md5 because of the String[] and String is different in main and md5 function,modify the code so it can run properly, also the input has to be entered from command line.

import java.security.*;
public class PasswordCracker {
public static void main (String[] args){
String password;
md5(args)
System.out.printf(""+password+"");

[code]....

View Replies View Related

Java Program Method To Calculate Distance

Feb 20, 2015

Write method distance, which calculates the distance between two points (x1, y1) and (x2, y2). All numbers and returned values should be of type double. Incorporate this method into an program that enable the user to enter the coordinates of the points, then calculate and display the distance by calling the method –distance.

I've tried numerous times to make it work and I'm on the right path, however I'm missing some things in the code to make my results look like this later on, which I've attached onto this post.

View Replies View Related

How To Call The Function String

Mar 17, 2015

import java.io.BufferedReader;
import java.io.InputStreamReader;
public class vowels{
public static void main(String arg [])
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a String : ");

[Code] .....

View Replies View Related

String Pool And Function Call

Aug 23, 2014

String pool puzzles me again. I think a==b and a==c are both true...

public class StringPoolTest {
public static void main(String[] args) {
String a = "abc";
String b = f() + "c";
String c = g();

[Code] .....

View Replies View Related

How To Call JavaScript Function From A Button

Dec 21, 2014

I an using a pop out java script and in the notes it says

if later on you want to open / close a specific item you could do it like so:

ExpandingMenu.openItem(3); // toggles item 3 (zero-based indexing)
*/

How to call the function from a button click. I have some button already on my page like so

<li><a href="#">Menu3</a></li>

And from what I have read I should be able to do this:

<li><a href="#" onclick="ExpandingMenu.openItem(3)">Menu3</a></li>

But I don't get any response ..... no error message NOTHING

View Replies View Related

Servlets :: How To Call JavaScript Function Or JQuery Modal Box

Mar 18, 2015

i don't need ordinary javascript alert box. so i was use the jquery modal alert box for different action like success, error etc.but i have problem to call the alert box within servlet.

out.println("<link href="css/jquery.modal.css" type="text/css" rel="stylesheet" />");
out.println("<script type="text/javascript" src="js/jquery-latest.min.js">");
out.println("<script type="text/javascript" src="js/jquery.modal.min.js">");
out.println("<script type="text/javascript" src="js/jscript.js">");
out.println("<script type="text/javascript" src="js/success.js">");
out.println("<script type="text/javascript">");
response.getOutputStream().println("success();");
out.println("</script>");

how to call the modal function in the js file?

otherwise how to show the modal alert box?

View Replies View Related

How To Calculate And Display Win / Loss For Two Different Teams Using Boolean Function And Arrays

Jan 28, 2015

I am still new to Java and have an assignment that I am stuck on. I believe I got the boolean function correct, however I cannot figure out what to write in the main function. I have exhausted searching, and trying different loops, arrays, etc.

View Replies View Related

Stored Function - Calculate Delivery Charges Given City And Weight

May 27, 2014

A stored function to calculate delivery charges given city and weight.
 
CREATE OR REPLACE FUNCTION CALCULATE_CHARGES
(
CITY IN VARCHAR2
, CHARGES IN NUMBER
, TOTAL IN NUMBER
) RETURN NUMBER AS
BEGIN
RETURN total:=city*charges;
END CALCULATE_CHARGES;

View Replies View Related

Method Is Declared To Take Three Arguments - Only Two Arguments Pass On Program Call

Jun 9, 2014

A method is declared to take three arguments. A program calls this method and passes only two arguments.Will it take the third argument as

1 null
2 void
3 zero
4 Compilation error

View Replies View Related

Call Variables From Main To Write To External File

Apr 27, 2015

I have this program, I am wondering if it is possible to call files from the main method and sort them into my saveOneRocord method? If so, how would that look?

my orderProcess Class

package stu.paston.finalprogram;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;
import java.io.File;
import java.io.PrintWriter;
import java.io.FileWriter;

[Code] .....

View Replies View Related

How To Call A Method That Exist Within A Class Into Main Method

Feb 13, 2014

I am just trying to test this array, for a locker combination program that involves classes...but the array is printing out the whacky numbers for the location. When I try to call the method in the main, it does not work. How do I call a method that exist within a class into the main method?

public class locker { 
public static void main(String[] args) {
CombinationLock();

[code]....

View Replies View Related

Recursive Method - Calculate Greatest Common Divisor Using Euclidean Method

Apr 29, 2014

Consider the following recursive method that calculates the greatest common divisor using Euclidean method.

PHP Code:

public static int GCD ( int x , int y )
{
    if ( y == 0 )                        
        return x;
    else if ( x >= y && y > 0)
        return GCD ( y , x % y );
    else return GCD ( y , x );  


Trace the above method for x=32 and y=46

View Replies View Related

Convert C# Function To Java Method

Dec 2, 2014

I need to convert c# function to java method. The important thing is String strKey. Parameters for testing are strMask= 4634958 and strSN=1394901184 and the result must be strKey = 2156325482!!! The result that I am getting with my Java code is 2138641814.This is C# code:

public static bool Key (String strMask, String strSN, ref String strKey)
{
System.UInt16 wLo, wHi;
System.UInt32 dwSNx, dwKey;
System.UInt32 dwSN, dwMask;
if (strMask=="") strMask="0";

[code]....

View Replies View Related

Method Call For A Void Method

Sep 29, 2014

I've never had to do a void method call. I have my void method in one class and my main (where I want to do the call) in another. How do you actually call a void method?

View Replies View Related

Function Calling In A Program?

Feb 12, 2015

I just wanted to ask that when we invoke a function by passing certain arguments in it ,so for instance I have certain variables like a,b and c with some values assigned to them,so when I invoke a function like func(a*b , 8, c+a) where the function func accepts parameters like func(int x,int y,int z) ,so is there any order of evaluation of expressions defined like the value of c+d would be evaluated first and then assigned to variable z ,because in C we have sequence points and since comma when acting like a separator is not a sequence point so any of the expression can be executed first ,so basically is there any sequence in which the function arguments are assigned to the parameters of the function or any relation with the stack implementation.

Even in C ,the printf starts executing its expressions from right to left so basically in why does it happen there when comma is a separator in a function argument.

View Replies View Related

How To Call Self Method

May 18, 2014

How to call/define/describe self method.. below is my code :

Java Code:

public static void main(String[] args) {
banana1();
banana2();
banana3();
banana4();
banana5();
banana6();

[code]....

how exactly to call a self method ?

View Replies View Related

How To Call Variable From Another Method

Oct 3, 2014

My code has a method where the users input a bunch of variables and then those variables get added together in a new variable. What I want to know is how do I call the variable that is in the other method to another method?

import java.util.*;
public class Calc{
public static void main (String [] args){
determinevalue1();
determinevalue2();
determineTotalvalue(double value1, double value2);

[Code] ....

View Replies View Related

Can Call A Method In If Else Statement?

Dec 6, 2014

I am trying to get the program to ask the user to enter the project grade and if it is less than 65, then I want the program to display "fail" or if it is greater than 64 than I want it to display "passed". In this project I have to include a method and I am trying to call it in my if-else statement. I keep getting an error message saying "Project.java:143: error: incompatible types: void cannot be converted to int". I posted my code below. It's a long program, but this part is toward the bottom.
 
import java.util.Scanner;
public class Project {
public static void main(String[] args) {
  //call method
welcomeMessage();
 
[Code] ....

View Replies View Related

Method Call Not Working?

Oct 30, 2014

I have two comboBoxes - one in main and another in my 'windows' class. The code below is in main and references the comboBox in main but I need to use the comboBoxEnv out of my 'windows' class. How can I do that so it says ComboBoxEnv rather than comboBox?

JMenuItem menuExport = new JMenuItem("Export");
menuExport.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(comboBox.getSelectedItem() == null){

[Code] ....

I've gotten access to it by changing my code and making a method of it but I'm not sure of what I do now

exportImport.comboBoxEnv();

View Replies View Related

How To Call Method Without Using Inner Classes

Jun 9, 2014

How do i call the method without using inner classes in this example:

jt = new JTable (model) {
public boolean isCellEditable (int row, int col) {
if (col == 5) {
return false;

[Code] ....

View Replies View Related

To Call Java Method In JSP

Apr 28, 2014

I am trying to call a java method in jsp. The main idea is to hide menu based on the user who logs in. The java class flows like this :

public class UserVerification {
public static void main(String[] args) {
UserVerification obj = new UserVerification();
System.out.print(obj.GetUserVerification("abc"));

[Code] ......

View Replies View Related







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