Text-Speed(Game) - David Raj
Text-Speed(Game) - David Raj
CODE :
import java.lang.*;
import java.util.*;
import java.time.*;
class Textspeed {
public static String easy(){
ArrayList<String> easym = new ArrayList<String>();
Random r = new Random();
easym.add("Everything you can imagine is real");
easym.add("Happiness depends upon ourselves");
easym.add("Live as if you were to die tomorrow");
easym.add("It always seems impossible until it's done");
easym.add("The time is always right to do what is right");
int a = r.nextInt(5);
return easym.get(a);
}
public static String medium(){
ArrayList<String> mediumm = new ArrayList<String>();
Random r = new Random();
mediumm.add("Normality is a paved road, it's comfortable to walk but no flowers grow");
mediumm.add("A simple life gives birth to more clarity, inner peace and meaningful relationships");
mediumm.add("Life is like riding a bicycle. To keep your balance, you must keep moving");
mediumm.add("I decided I can't pay a person to rewind time, so I may as well get over it");
mediumm.add("The best way to appreciate your job is to imagine yourself without one");
int a = r.nextInt(5);
return mediumm.get(a);
}
public static String hard(){
ArrayList<String> hardm = new ArrayList<String>();
Random r = new Random();
hardm.add("Do not confuse motion and progress. A rocking horse keeps moving but does not make any progress");
hardm.add("There is a great difference between worry and concern. A worried person sees a problem, and a concerned person solves a problem");
hardm.add("Somewhere on this globe, every ten seconds, there is a woman giving birth to a child. She must be found and stopped");
hardm.add("The most remarkable thing about my mother is that for thirty years she served the family nothing but leftovers. The original meal has never been found");
hardm.add("You know you're getting old when you stop to tie your shoelaces and wonder what else you could do while you're down there");
int a = r.nextInt(5);
return hardm.get(a);
}
public static void check(String str, int n){
Scanner sc = new Scanner(System.in);
boolean count=false;
System.out.println("\n"+str+"\n");
System.out.println("Enter your text Below :\n");
float start = time();
String str1=sc.nextLine();
float end = time();
float total = end - start;
if(total<n){
if(str.equals(str1)){
System.out.println("\nSuccesfully Completed");
System.out.println("\nYour time is : "+(end-start)+" seconds");
}
else{
System.out.println("\nSorry U've Failed!!");
}}
else{
System.out.println("\nSorry Timeout!!");}
}
public static float time(){
float tim = System.nanoTime();
float m = tim/1000000000;
return m;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int select_mode = 0;
while(true){
System.out.println("\n1.Easy 2.Medium 3.Hard 4.Exit");
select_mode = sc.nextInt();
switch(select_mode){
case 1: System.out.println("Easy mode Selected");
check(easy(),30);
break;
case 2: System.out.println("Medium mode Selected");
check(medium(),50);
break;
case 3: System.out.println("Hard mode Selected");
check(hard(),70);
break;
default : return;
}
}
}
}
Output :
1.Easy 2.Medium 3.Hard 4.Exit
2
Medium mode Selected
A simple life gives birth to more clarity, inner peace and meaningful relationships
Enter your text Below :
A simple life gives birth to more clarity, inner peace and meaningful relationships
Succesfully Completed
Your time is : 5.276256 seconds