Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- */import java.util.Scanner;
- public class JavaApplication22 {
- public static void BMI(){
- Scanner a = new Scanner(System.in);
- System.out.println("Please enter your weight in kilogram");
- double weight = a.nextDouble();
- System.out.println("Please enter your height in meter");
- double height = a.nextDouble();
- double BMI = (weight/(height*height));
- System.out.println("Your BMI rating is " + BMI);
- }
- public static void coin(){
- Scanner b = new Scanner(System.in);
- System.out.println("Please enter your amount of coins");
- int coin = b.nextInt();
- int quan = coin/10000;
- int dong = coin%10000/100;
- int hao = coin%10000%100/10;
- int xu = coin%10000%100%10;
- System.out.println("You have " + quan + " quan, " + dong + " dong, " + hao + " hao, " + xu + " xu.");
- }
- public static void leap(){
- Scanner c = new Scanner(System.in);
- System.out.println("Please enter the year you want to check");
- int y = c.nextInt();
- String a = "The year " + y + " is not a leap year";
- String b = "The year " + y + " is a leap year";
- if (y % 4 != 0){
- System.out.println(a);
- }else
- if (y % 100 != 0 ){
- System.out.println(b);
- }else
- if ( y % 400 != 0 ){
- System.out.println(a);
- }else
- System.out.println(b);
- }
- public static void quadratic(){
- int a, b, c;
- double root1, root2, d;
- Scanner s = new Scanner(System.in);
- System.out.println("Given quadratic equation:ax^2 + bx + c");
- System.out.print("Enter a:");
- a = s.nextInt();
- System.out.print("Enter b:");
- b = s.nextInt();
- System.out.print("Enter c:");
- c = s.nextInt();
- System.out.println("Given quadratic equation:"+a+"x^2 + "+b+"x + "+c);
- d = b * b - 4 * a * c;
- if (a==0 && b==0 && c==0){
- System.out.println("There is nothing to be solved");
- }else
- if (a==0 && b==0 && c != 0){
- System.out.println("The equation has no root");
- }else
- if (a==0 && b !=0 && c !=0){
- double x = -c/b;
- System.out.println("X= " + x);
- }else
- if (d < 0){
- System.out.println("The equation has no real root");
- }else
- if (d > 0){
- double x1 = ((-b + Math.sqrt(b*b-4*a*c))/(2*a));
- double x2 = ((-b - Math.sqrt(b*b-4*a*c))/(2*a));
- System.out.println("The equation has two roots : x1 = " +x1 + "," + "x2 = " +x2);
- }
- }
- public static void strength(){
- Scanner e = new Scanner(System.in);
- System.out.println("Please enter the password you wish to be evaluated");
- String password= e.nextLine();
- int strength= 0;
- boolean upper= false, lower= false, digit= false, symbol= false;
- if (password.length()>=8 && password.length()<=12)
- {
- strength+=1;
- }
- else if (password.length()>12)
- {
- strength+=2;
- }
- for (int i=0; i< password.length(); ++i) // uppercase checker
- {
- if (password.charAt(i)>= 'A' && password.charAt(i)<= 'Z')
- {
- upper= true;
- continue;
- }
- else if (password.charAt(i)>= 'a' && password.charAt(i)<= 'z')
- {
- lower= true;
- continue;
- }
- else if (password.charAt(i)>= '0' && password.charAt(i)<= '9')
- {
- digit= true;
- continue;
- }
- else
- {
- symbol= true;
- }
- }
- if (upper == true)
- {
- strength+=1;
- }
- if (lower == true)
- {
- strength+=1;
- }
- if (digit == true)
- {
- strength+=1;
- }
- if (symbol == true)
- {
- strength+=1;
- }
- if (strength<=2)
- {
- System.out.println("Your password strength: " + strength+ " (weak)");
- }
- else if (strength <=4)
- {
- System.out.println("Your password strength: " + strength+ " (medium)");
- }
- else
- {
- System.out.println("Your password strength: " + strength+ " (strong). Make sure you do not forget it.");
- }
- }
- public static void GCD(){
- Scanner f= new Scanner(System.in);
- System.out.println("Enter two positive integers of which you wish to find the GCD");
- int a= f.nextInt();
- int b= f.nextInt();
- while (a<=0 || b<=0)
- {
- System.out.println("The program does not allow negative or zero values! Please try again.");
- a= f.nextInt();
- b= f.nextInt();
- }
- if (a<b)
- {
- int temp= a;
- a=b;
- b=temp;
- }
- while (true)
- {
- if (a%b==0)
- {
- break;
- }
- int temp=a;
- a= b;
- b= temp%b;
- }
- System.out.println("The GCD is: "+ b);
- }
- public static void main(String[] args) {
- Scanner f = new Scanner(System.in);
- System.out.println("[1] BMI calculator");
- System.out.println("[2] Coin converter");
- System.out.println("[3] Leap year checker");
- System.out.println("[4] Quadratic equation solver");
- System.out.println("[5] Password strength meter");
- System.out.println("[6] GCD finder");
- System.out.println("[7] Quit");
- System.out.println("Choose an option");
- int n = f.nextInt();
- while (n !=7)
- {
- switch (n)
- {
- case 1:
- BMI();
- break;
- case 2:
- coin();
- break;
- case 3:
- leap();
- break;
- case 4:
- quadratic();
- break;
- case 5:
- strength();
- break;
- case 6:
- GCD();
- break;
- }
- System.out.println("[1] BMI calculator");
- System.out.println("[2] Coin converter");
- System.out.println("[3] Leap year checker");
- System.out.println("[4] Quadratic equation solver");
- System.out.println("[5] Password strength finder");
- System.out.println("[6] GCD finder");
- System.out.println("[7] Quit");
- System.out.println("Choose an option");
- n = f.nextInt();
- }
- System.out.println("Program exited");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement