In: Computer Science
COP 2800, Java Programming
Assignment 6-1
Using Java create a program using the “Methods” we covered this week. come up with a “problem scenario” for which you can create a “solution”. Utilize any/all of the examples from the book and class that we discussed. Your program should be interactive and you should give a detailed statement about what the “description of the program – purpose and how to use it”. You should also use a “good bye” message. Remember to discuss in your “reflection” the advantage of using “methods” – we discussed “re-usability” and “modularity”. Write detail comments on the program.
You need to include all the following:
Static Methods
Library methods and user written methods
Non Static Methods (Class & Object)
Methods with arguments
Methods without arguments
Conditional statements
Loops
For Example: (you could come up with any other program) - use your creativity Welcome to my “multifunction” program. In this program I have an interactive program to show the use and benefits of “methods” in Java program. You will see a “selection menu” that would allow you to use the program.
Choose 1. For your “compound interest calculator” of your “retirement nest” income, 2. For your “Interactive input of Employee attributes and then display of their attributes”, 3. For your….
Thank you for using my “multifunction” program. Have a nice day.
Save the below as Main.java
/******************************************************************************
Java program to illustrate static methods, library methods, non
static methods,
methods with arguments, methods without arguments, conditional
statements,
loops
*******************************************************************************/
public class Main
{
static void staticMethod()
{
System.out.println("Hello World!");
}
void nonStaticMethod()
{
System.out.println("Test");
}
static int maxim(int a, int b)
{
//Conditional statement
if(a>b)
return a;
else
return b;
}
public static void main(String[] args) {
//Calling static method without
arguments
staticMethod();
//Calling library method with
arguments
int maximum = Math.max(3,4);
System.out.println(maximum);
//Calling user written method with
arguments
maximum = maxim(4,5);
System.out.println(maximum);
//Calling non static method
//nonStaticMethod();//throws error,
so have commented
//Loop
for(int i = 0; i < 3; i++)
System.out.print("good bye!
");
}
}