Nick V.

asked • 04/13/14

Help Creating Java Program Menu, Classes, and Quit function

I am creating a java program and I do not know how to put my 3 functions into it.
I also need some sort of menu screen and a way to quit the program.
These are my only guidelines:
 
• You must create separate class for the each function.
• There should be one class that contains the main method and that should also display the menu from where user can choose the options. So there should be total 4 java files.
• You must use proper naming convention for classes, objects, variables, etc.
 
Here are the 3 functions.
 
Programs 1 :


import java.util.Scanner;

class Factorial
{
public static void main(String args[])
{
int n, c, fact = 1;

System.out.println("Enter an integer to calculate it's factorial");
Scanner in = new Scanner(System.in);

n = in.nextInt();

if ( n < 0 )
System.out.println("Number should be non-negative.");
else
{
for ( c = 1 ; c <= n ; c++ )
fact = fact*c;

System.out.println("Factorial of "+n+" is = "+fact);
}
}
}
 
 
 
Program 2

import java.util.Scanner;

public class FibonacciSeries {

public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Enter the value of n: ");
int n = s.nextInt();
fibonacci(n);
}

public static void fibonacci(int n) {
if (n == 0) {
System.out.println("0");
} else if (n == 1) {
System.out.println("0 1");
} else {
System.out.print("0 1 ");
int a = 0;
int b = 1;
 
 
Program 3:
 
 
import java.util.Scanner;

class MultiplicationTable
{
public static void main(String args[])
{
int n, c;
System.out.println("Enter an integer to print it's multiplication table");
Scanner in = new Scanner(System.in);
n = in.nextInt();
System.out.println("Multiplication table of "+n+" is :-");

for ( c = 1 ; c <= 10 ; c++ )
System.out.println(n+"*"+c+" = "+(n*c));
}
}
 
 

2 Answers By Expert Tutors

By:

Larry C. answered • 04/24/14

Experienced programmer, analyst, database designer and administrator

Patrick B. answered • 06/06/19

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.