Jack Johnson
New member
Main
import java.util.Scanner;
public class Worksheet_4
{ public static void main(String [] args)
{ Scanner Fred = new Scanner(System.in);
String Name;
System.out.println("Today we practice writing methods ");
Practice object1 =new Practice(6, '$');
System.out.println("Object 1 is: " + object1);
object1.Story();
Practice myObject = new Practice(34, '#');
myObject.Story();
long MyNum = object1.SixTimes();
System.out.println("MyNum is: " + MyNum);
System.out.println("\n\n\n");
}
}
Practice method
public class Practice
{ private int Number;
private char Thing;
public Practice(int Num, char Ans)
{ Number = Num;
Thing = Ans;
}
public String toString()
{ String Result;
Result = "Number is: " + Number + "Thing is: " + Thing;
return Result;
}
public void Story()
{ System.out.println("This is a cute little method that only prints things");
System.out.println("First we will print the value of the integer: " + Number);
System.out.println("Now we print the character: " + Thing);
System.out.println("Number and Thing are called instance variables");
System.out.println("And now we are done
");
}
public long SixTimes()
{ long BigNum;
BigNum = Number*Number*Number*Number*Number*Number;
return BigNum;
}
}
I need to call the method SixTimes() with the object myObject, but im not sure what to do
import java.util.Scanner;
public class Worksheet_4
{ public static void main(String [] args)
{ Scanner Fred = new Scanner(System.in);
String Name;
System.out.println("Today we practice writing methods ");
Practice object1 =new Practice(6, '$');
System.out.println("Object 1 is: " + object1);
object1.Story();
Practice myObject = new Practice(34, '#');
myObject.Story();
long MyNum = object1.SixTimes();
System.out.println("MyNum is: " + MyNum);
System.out.println("\n\n\n");
}
}
Practice method
public class Practice
{ private int Number;
private char Thing;
public Practice(int Num, char Ans)
{ Number = Num;
Thing = Ans;
}
public String toString()
{ String Result;
Result = "Number is: " + Number + "Thing is: " + Thing;
return Result;
}
public void Story()
{ System.out.println("This is a cute little method that only prints things");
System.out.println("First we will print the value of the integer: " + Number);
System.out.println("Now we print the character: " + Thing);
System.out.println("Number and Thing are called instance variables");
System.out.println("And now we are done
}
public long SixTimes()
{ long BigNum;
BigNum = Number*Number*Number*Number*Number*Number;
return BigNum;
}
}
I need to call the method SixTimes() with the object myObject, but im not sure what to do