Method From Main - Calculate Weight On Different Planets

Nov 8, 2014

I have to write a program to calculate my weight on different planets and to do that, I have to read in the surface gravity of all the planets from a file using a separate method from main

public static double[] readGravity() throws IOException
{
double[] surfaceGravity = new double[8];
Scanner readFile = new Scanner("gravity1.txt");
int i = 0;
while (readFile.hasNext()) {
surfaceGravity[i] = readFile.nextDouble();
i++;
}
return surfaceGravity;
}

I get this message in the while loop when I try to run the program:

java.util.InputMismatchException;
null (in java.util.Scanner)

View Replies


ADVERTISEMENT

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

Calculate Shipping Charges Based On Product Weight In Pounds And Distance In Miles

Mar 26, 2014

I want to write a Utility to calculate the shipping charges based on the product weight in pounds and distance in miles. How we can go about it.

View Replies View Related

Orbiting Planets And Moons

May 4, 2014

I'm trying to make a code that has several orbiting images, a moon orbiting the earth, and then a smaller moon orbiting the moon. Getting the main moon orbiting the earth wasn't too difficult, it just requires rotating the moon image around the center of the earth. However, how to get the smaller moon rotating around the big one. How to do this? The images I'm using are attached.

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JFrame;

[Code] .....

Moon.jpgoie_transparent.jpgRocket.jpgGalaxy2.jpg

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

How To Return Array From A Method / Back Into Main Method That Prints Out Stuff

May 27, 2014

I'd like to know how to return a new array, I wrote in a method below the main method. I want to print the array but system.out.print doesn't work for arrays apparently. What structure i should use?

View Replies View Related

Writing A Method That Returns Words Without Four Letters Back To Main Method

May 27, 2014

I have to write a method called censor that gets an array of strings from the user as an argument and then returns an array of strings that contains all of the original strings in the same order except those with length of 4. For example if cat, dog, moose, lazy, with was entered, then it would return the exact same thing except for the words with and lazy.

Currently, my code so far just prints [Ljava.lang.String;@38cfdf and im stuck.

import java.util.Scanner;
 public class censorProgram {
public static void main (String args[]){
Scanner input = new Scanner (System.in);
System.out.println ("How many words would you like to enter?");
int lineOfText = input.nextInt();
 
[Code] ....

I have to make new string array in the method and return words without four letters in the main method

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

Main Method Separated From Other Method

Jan 13, 2014

Here's a class called Fibonacci

Java Code:

public class Fibonacci {
public static int fib(int n) {
if (n < 2) {return n;}
else {return fib(n-1)+fib(n-2);}

[code]....

it contains one method called fib() and one main method.If I would want to have the main method in another class than fib(), how would I write the two classes? Only cutting the main method from this class to another one doesn't work.My question is, is the reason it doesn't work because I then would have to have a constructor in the Fibonacci class, and create a Fibonacci object first which I then use the method on?

View Replies View Related

No Main Method?

Jul 23, 2014

I'm trying to make a TBG (Text Based Game) in Java for Android. Now, when I try to run it, it says No Main Method to run this program. The compiler also checks the program and tell me there are no errors.

View Replies View Related

Program For Weight Conversion GUI

Apr 21, 2015

I'm working on a Weight Conversion program. The code I have for the program is:

import java.util.*;
import java.awt.*;
import javax.swing.*;
public class Frame4a implements ActionListener {
public static void main(String[] args) {
JFrame f = new JFrame("Weight converter");
JPanel P = new JPanel(); // Make a JPanel;

[Code] .....

The errors I'm getting are:

Frame4a.java:33: error: class, interface, or enum expected
public void actionPerformed(ActionEvent e){
^
Frame4a.java:37: error: class, interface, or enum expected
double kp= Double.parseDouble(strkilo);

[Code] .....

View Replies View Related

Why Is Main Method Static

Oct 1, 2014

in java why main method is always static in nature...

View Replies View Related

Calling A Method From Main

Jan 26, 2014

The idea is to create a program to add plants and retrieve plants from a Nursery. I created a class with the properties of the plants and also there is the class an Array list to keep track of the plants entered ( they will have to be printed later) (I am not too sure if adding a public class there is the best option.

The program will allow the user to pick and action and from there the code will do something. I don't want to have all the code inside 'main' The problem is in line 114.This is what I have so far.

Java Code:

package plant.nursery;
import java.util.ArrayList;
import java.util.Scanner;
/**Class to create a plant for a nursery.
public class PlantNursery

[code]....

View Replies View Related

Define Main Method

Apr 26, 2014

this is my program error occured run time,but compile sucessfully

{error msg-Error: Main method not found in class helloworldapp.HelloWorldApp, please define the main method as:
public static void main(String[] args)}
class HelloWorldApp
{
private int empno;
private float salary;
void setHelloWorldApp()
{
empno=12;
salary=1200;

[code]....

View Replies View Related

Calling A Method To Main

Nov 17, 2014

I'm trying to call a method to my main method, but I can't seem to get it to work and it keeps resulting in a compile error.

import java.io.*;
import java.awt.Point;
import java.text.DecimalFormat;
import java.util.Random;
public class Chase {
public static void main(String args[]){

[Code] .....

View Replies View Related

Calling A Method To The Main

Sep 10, 2014

I have been reading about methods and I do have a beginner level understanding on how they work. I was trying to mess around and make a dog calculator using methods. I ran into a small snag; I cannot get the method to call to the main or the program to compile correctly. The first code below is the original. To me it looks like (based off of some examples I looked at) there should be no problems, but NetBeans gives me a few errors. 1) line 8- "cannot find symbol, variable dogYearCalc; 2) line 18 illegal start of expression; and 3) line 22 - unreachable statement.

import javax.swing.JOptionPane;
public class KrisExample {
public static void main (String[] args) {
double dogYears = 0;
JOptionPane.showInputDialog (null,"Please enter you dog's age in human years:");

[Code] ....

Someone told me that I was calling dogYearCalc without any arguments in your main method. I take that to mean that I needed to add it to the main, so I did here:

public static void main (String[] args, double dogYearCalc) {

That got rid of my first error, but then when I tried to run the program NetBeans said that I have no main class, so switched back to the original program above.

I thought that when I calling the dogYearCalc method on line 10 was the whole purpose of using a method. It seems to me that putting it somewhere in the main is counter productive.

View Replies View Related

Trying To Calculate Fine Using Method Calls

Jul 3, 2014

I am trying to calculate a fine in a PoliceOfficer object with method calls to a ParkedCar and ParkingMeter object. The word problem is:

The fine is $25 for the first hour or part of it and $20 for every additional hour of part of it.

My code is:

public class PoliceOfficer
public static final int PARKING_FINE1 = 25;
public static final int PARKING_FINE2 = 20;
public static final int NUMBER_OF_MINUTES_OVER_PARKED = 60;
public double calculateFine(){
double calculateFine = 0;

[Code] ....

obviously the fine is not calculated correctly but I'm not sure how to proceed from here...

View Replies View Related

Calculate PI Using Monte Carlos Method

Aug 10, 2014

I've been looking at the calculating PI using Monte Carlos method. All of the codes request an input from the user to be able to determine PI. However, I want the program to print out only 10, 100, 1000, 10000, 100,000 and 1,000,000,000 for PI.

Here is the link to the original post ...

View Replies View Related

How To Calculate Remove Method Complexity

Feb 1, 2015

I need to figure out how to calculate the remove method complexity in the worst best and average case same as the insert method

public void insert(String Word)
{
size++;
int pos = myhash(Word);
WordNode nptr = new WordNode(Word,null);
if (table[pos] == null)
table[pos] = nptr;

[Code] .....

View Replies View Related

Two Weight In Kilograms And Grams - Print Sum

Oct 22, 2014

Write a program which request two weight in kilograms and grams and print the sum of the weight, if the weight are 3kg 500g and 4kg 700g, your program should print 8kg 200g. this is what i have

Scanner input = new Scanner (System.in);
double weight, kg, g;
int sum;
System.out.println("Please enter weight");
weight = input.nextDouble();

[Code] .....

View Replies View Related

Recall Main Method After Calling Of JVM?

Jul 28, 2014

Can we recall the main method? I'm trying a code to recall main method (after the calling of JVM). I know this doesn't make any sense but I'm trying this just like that.

Code:

class derived {
public static void main(String args[]) {
System.out.println("Main Method class");
show();
}
static void show()

[code]....

View Replies View Related

Splitting Up Main Method / Class?

Jan 29, 2014

I've written a program just for the sake of it (to learn) and it seem's like theres quite a lot in the main method that perhaps could be split up into seperate classes. I'm not too sure where should start with this though, or what my thought process should have been as I was writing the program.

import java.util.Scanner;
 public class Loops {
 public static void main(String[] args) { 
int answer = 16; 
Scanner scan = new Scanner(System.in); 
// Question
 System.out.println("What is 4 x 4 ?"); 

[code]...

--- Update ---

here's a version without code comments as they might make it harder to read here -

import java.util.Scanner;
 public class Loops {
 public static void main(String[] args) {
 int answer = 16;
 Scanner scan = new Scanner(System.in);
 System.out.println("What is 4 x 4 ?");
 int userAnswerInt = 0;

[code]...

View Replies View Related

Void And Static In Main Method?

Jan 7, 2014

What does void and static mean in the main method?

View Replies View Related

How To Have Multiple Classes But Only One Main Method

Nov 1, 2014

I was reading the book, "Head First Java" and it was talking about how there may be multiple classes in a large application, but there will be only one main method.how does it work that way? How can you have multiple classes, but only one main method?

View Replies View Related

Access A Method Of Class From Main

Feb 9, 2014

This time I have to make a Black Jack game ( I guess this is a classic) I have created Three classes for this BlackJack( Main), Card, and Player.

What I am trying to do is put the Give one card to the player and remove it from the deck into a separate procedure because I will be doing this several times during the game.

This is the code I have so far Under the class BlackJack.

Java Code:

package black.jack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

[Code] .....

View Replies View Related

Cannot Call Child Method From Main

May 7, 2015

I can call a child method from a main method. If I have a parent called "Assessment", a child called "Quiz", and another child called "test". Can I instinate an object like Assessment a = new test(); and call a method in test.I know the method can be called if I instinate the test t = new test() but that defeats the purpose of inheritance which I'm learning in class.

View Replies View Related







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