I am having a block - I am writing a program that will receive a series of numbers entered in by the user. I need to test to make sure that the number is not negative but also that I truly have a number (not a letter or special character). The first part is easy
if (numbEntered[x] <0)...
Thank you so much for your words of wisdom. I actually figured it out - there was an existing array at the beginning of my class that I was able to call in. I always look at things the hard way.
Also I should probably just point out that I am taking a workshop to learn java - it is a no...
I have to set it up this way because it is an assignment. I am suppose to make the toString method print out the column headings and then populate the data that follows. I guess my biggest problem is how to get the data from another method into the different subsets of the array. I have tried...
Thanks for the responses.
Bob,
This array is where I am struggling. Do I call the methods for getting the month, getting the data and calcualting into the subsets of the array? This should probably be the easy part but it is just not clicking.
I am trying to write a program where the user enters in the average and actual rainfall amounts for 12 months. Then the system will display the month, actual, average and the difference in a table layout -
Month Actual Average Difference
Jan 5 3 2
Feb...
I have a static method I wrote:
public static Money add(Money money1, Money money2)
{
int newDollars = money1.getDollars() + money2.getDollars();
int newCents = money1.getCents() + money2.getCents();
if (newCents >= 100)
{
newDollars++;
newCents -= 100;
}
return new Money(newDollars...
I tried that - now I get this compile error:
C:\Documents and Settings\NextStep\Desktop\OdometerA.java:13: missing return statement
}
^
C:\Documents and Settings\NextStep\Desktop\OdometerA.java:18: missing return statement
}
^
C:\Documents and...
I am trying to write a get method:
public void getGasConsumed()
{
int gals = miles/fuelEffiency;
return gals;
}
when I try to compile it I get the following error:
cannot return a value from method whose result type is void
return gals;
I am not understanding the problem - any help...
I have a program that I need to convert the existing methods to get and set methods but I am struggling with how to do this. I have one set in place. Can anyone help in changing some of the others to get or set as appropriate? Any help is appreciated.
TJ
Here is the code:
import...
I am trying to right a program that calculates MPG of a car and then resets the odometer.
I set up a class for the odometer and then am trying to call in the different methods into main.
Here is the odometer class:
import java.util.Scanner;
public class Odometer
{
public int milesDriven...
I am trying to right a program that calculates MPG of a car and then resets the odometer.
I set up a class for the odometer and then am trying to call in the different methods into main.
Here is the odometer class:
import java.util.Scanner;
public class Odometer
{
public int milesDriven...
I am writing a program that based on what you enter will determine how much your change will be - it then displays the total of each coin.
The problem is my math - the dimes are not computing right so it gives back more nickles then necessary. Can someone set me straight here. I think other...
I changed it to use the replaceFirst:
/**
Replaces the first occurrence of "hate" in a String with the word "love".
*/
public class LoveHate
{
/**
The String in which a word is to be replaced
*/
public static final String ORIGINAL = "I hate you.";
public static void...
I am new to Java so I am trying to write some simple applications that I will need to enhance later for a new project I need to implement.
The program I am writing should be simple. It removes one word from a statement and changes it with another. I thought a simple getChars would do it but...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.