Hi, I'm a student, and yes, I'm looking for help with and assignment. However, I'm not looking for an easy way out of my assignment... I'm just lost. I need help understanding how I need to change my code.
I particularly need help here:
//** The method displayHeading displays your name, BlazerID, course name, and your
//** row number and seat number. The course name is passed as a parameter. ** 1 point
myObject.displayHeading("CS-201");
public void displayHeading(String course)
{
System.out.println("\n\nBen Giles");
System.out.println("bengiles");
System.out.println(course);
System.out.println("Row Number: 2 Seat Number: 5\n");
}
I'm pretty lost. I don't understand what's going on exactly. I know this is simple, but I don't really understand methods. I'm reading the tutorial on Classes at
java.sun.com/docs/books/tutorial/java/ right now, so maybe I'll understand what's going on at this point in the code before anyone answers. However, any explanation about this section (and my mistakes) would be greatly appreciated. Thank you!
Here's the full thing:
import java.util.Scanner;
public class MyClass456
{
public static void main (String[] args)
{
Scanner scan = new Scanner(System.in);
MyClass456 myObject = new MyClass456(); // Replace NNN with 456.
// At the actual exam use your test number.
int n1, n2, n3, i;
//** The method displayHeading displays your name, BlazerID, course name, and your
//** row number and seat number. The course name is passed as a parameter. ** 1 point
myObject.displayHeading("CS-201");
public void displayHeading(String course)
{
System.out.println("\n\nBen Giles");
System.out.println("bengiles");
System.out.println(course);
System.out.println("Row Number: 2 Seat Number: 5\n");
}
//** method testSigns(n1,n2,n3) returns the String:
//** "All Positive or Zero" if all three parameters are zero or positive ( >= 0 )
//** "All negative" if all three parameters are negative ( < 0 )
//** "Postive and Negative" if parameters are mixed signs ** 4 points
//** Example: calling testSigns(-1,3,0) returns "Positive and Negative"
//** Example: calling testSigns(10,13,0) returns "All Positive or Zero"
//** Example: calling testSigns(-2,-7,-12) returns: "All Negative"
for (i = 0; i < 3; i++) // test method testSigns three times
{
System.out.print("\n\n** method testSigns **\n\nEnter the first positive," +
"negative, or zero integer: ");
n1 = scan.nextInt();
System.out.print("\nEnter the second positive, negative, or zero integer: ");
n2 = scan.nextInt();
System.out.print("\nEnter the third positive, negative, or zero integer: ");
n3 = scan.nextInt();
System.out.println("\n" + n1 + " " + n2 + " " + n3 + ": " +
myObject.testSigns(n1, n2, n3));
}
public String testSigns(int x, int y, int z)
{
if (x >= 0 && y >= 0 && z >= 0)
return "All Positive or Zero";
else
if (x < 0 && y < 0 && z < 0)
return "All Negative";
else
return "Postive and Negative";
}
//** Method oddNumbers(n1, n2) displays the odd numbers
//** from integers n1 to n2 (inclusive)
//** The odd numbers are displayed one per line.
//** Examples: oddNumbers(1,5) displays: 1 oddNumbers(10,18) displays 11
//** 3 13
//** 5 15
//** ** 5 points 17
System.out.print("\n\nEnter the first integer: ");
n1 = scan.nextInt();
System.out.print("\n\nEnter the second integer: ");
n2 = scan.nextInt();
myObject.oddNumbers(n1,n2);
System.out.println();
public void oddNumbers(int start, int finish)
{
while (start <= finish)
{
if (start % 2 != 0)
System.out.println(start);
start++;
}
}
}
}