Instantly share code, notes, and snippets.

Embed
What would you like to do?
Template For Java Homework and Projects
/*
* Name:
* Date:
* Course Number:
* Course Name:
* Problem Number:
* Email:
* Short Description of the Problem
*/
import java.util.Scanner;
public class TemplateForProjects {
//**********************************************
private static void process(Scanner sc, String args[]) {
// Code here is merely a sample
int x;
System.out.print("Enter value: ");
x = sc.nextInt();
sc.nextLine(); // IMPORTANT!! Reset Scanner
System.out.println("Processing " + x + " ...");
}
//**********************************************
private static boolean doThisAgain(Scanner sc, String prompt) {
System.out.print(prompt);
String doOver = sc.nextLine();
return doOver.equalsIgnoreCase("Y");
}
//**********************************************
public static void main(String args[]) {
final String TITLE = "CSC111 Project Template";
final String CONTINUE_PROMPT = "Do this again? [y/N] ";
System.out.println("Welcome to " + TITLE);
Scanner sc = new Scanner(System.in);
do {
process(sc, args);
} while (doThisAgain(sc, CONTINUE_PROMPT));
sc.close();
System.out.println("Thank you for using " + TITLE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment