r/ProgrammingPrompts • • Jan 07 '15

[EASY][Beginner] UAGS (Universal Acronym Generating System)

This is an extremely simple prompt, just for fun.

It is suitable for beginners as it only uses basic input/output and string manipulation.

UAGS (Universal Acronym Generating System)

Acronyms are currently all the hype in all forms of communication.

Your task is to program an Acronym Generator.

  • The user inputs a few words for which the Acronym should be generated
  • The computer takes the first letter for each word
  • The first letter of each word is then capitalized
  • All first letters are then joined together to form the Acronym
  • The Acronym should then be printed
  • Ask the user if they need another acronym generated

Have fun coding!

14 Upvotes

27 comments sorted by

View all comments

1

u/SolarFloss Mar 17 '15 edited Mar 17 '15

Made in Java. I'm new to this, so please give me some tips!

import java.util.Scanner;

public class MainClass{
public static void main(String[] args){
	MakeAcronym();
}

public static void MakeAcronym(){
	Scanner console = new Scanner(System.in);
	String sentence;
	String response;
	String acronym = null;
	System.out.println("~~Acronym Maker 3000!~~");
	System.out.print("\n\nSay a cool sentence: ");
	sentence = console.nextLine();
	
	for(int i = 0; i < sentence.length(); i++){
		if(i > 0){
			if(sentence.substring(i-1,i).equals(" ")){
				acronym += sentence.substring(i,i+1).toUpperCase();
			}
		}else{
				acronym = sentence.substring(0,1).toUpperCase();
		}
	}
	
	System.out.println("\n\nYour new acronym: " + acronym);
	System.out.print("\n\nAgain?[y/n]: ");
	response = console.nextLine();
	if(response.equals("y")){
		MakeAcronym();
	}else if(response.equals("n")){
		System.out.println("TELL YOUR FRIENDS. Goodbye");
		System.exit(0);
	}else{
		System.out.println("Not a valid response. Closing!");
		System.exit(0);
	}
}
}