Class? Method? Parameter? I can't get my feeble noggin around these things at all.
I'm taking a java class at school and we've been given an assignment to work on. I don't really have time to talk to the teacher as she's booked solid. I knew I should have made an appointment earlier!
So I know how much you guys hate to be bothered with a newb's homework, but I thought I'd give it a shot. I'm not looking for anyone to write my code for me as that would be counterproductive since I will be having a midterm and final in the class.
So I'll post the instructions my teacher gave and then post the minuscule bit of code I've done (and I'm sure it's wrong as Eclipse gives me errors that I can't seem to fix, try as I might).
As you can see I'm stuck on step 1.... but maybe after a little help from you guys I'll be able to knock the rest of the code out without anyone holding my hand.
I don't want to start with the other steps until I've perfected the first.
I'm taking a java class at school and we've been given an assignment to work on. I don't really have time to talk to the teacher as she's booked solid. I knew I should have made an appointment earlier!
So I know how much you guys hate to be bothered with a newb's homework, but I thought I'd give it a shot. I'm not looking for anyone to write my code for me as that would be counterproductive since I will be having a midterm and final in the class.
So I'll post the instructions my teacher gave and then post the minuscule bit of code I've done (and I'm sure it's wrong as Eclipse gives me errors that I can't seem to fix, try as I might).
As you can see I'm stuck on step 1.... but maybe after a little help from you guys I'll be able to knock the rest of the code out without anyone holding my hand.
- Method 1:
Write a public static method named myUserName. This method does not return anything. This method accepts no parameters. This method simply prints out your engr username (all lowercase letters). For example, mine prints out
wallacch- Before going on to the next method, you should write a main method and use it to test your myUserName method. Never turn in code that you haven't tested!!!
So, do you remember how to call a static method?
(Your main method can be inside the Project1 class OR it can be in a new class all by itself.) As you complete the other 4 methods of this assignment, add more code to this main method to thoroughly test each of the 5 methods of this assignment.- Method 2:
Write a public static method named mathConstants. This method does not return anything. This method accepts no parameters. This method simply has two print statements. The first one prints out:
PI = 3.141592653...
The second print statement prints out:
e = 2.7182818284...
I didn't show you all the digits because I didn't want you to type in the digits. I want you to use the constants in the Math class.
Math.PI
Math.E
Just concatenate the String "PI = " with Math.PI (use the + operator).
Do the same with "e = " and Math.E
If you do this correctly, the print statements will show 15 digits to the right of the decimal point.- Method 3:
Write a public static method named myUserName2. This method returns a String. This method accepts no parameters. The only thing this method does is to return a String that is your engr username in all lowercase. Do not print it, return it. For example, my method returns
"wallacch"- Method 4:
Write a public non-static method named first10. This method returns an int. Do not use print statements in this method. This method accepts an int parameter. This method adds up the first 10 ints [1 - 10] and then multiplies the sum by the int parameter and returns that number.
For example, if the int parameter is 3, then this method returns (1+2+...+10) * 3.
If the int parameter is 42, then this method returns (1+2+...+10) * 42.- Method 5:
Write a public non-static method named isEven. This method returns a boolean. This method accepts an int parameter. This method returns true if the parameter is even. This method returns false if the parameter is odd. (Hint: use the % operator.)
This method does NOT print anything, it returns a boolean. Test this method by calling it from a main method. Print out what this method returns in main, not in isEven.
Code:
public class Project1 {
public static void main(String[] args) {
public static void myUserName()
{
System.out.println("myLastNamej")
}
}
//note that myLastNamej is just a place holder for my actual last name
}
I don't want to start with the other steps until I've perfected the first.