Untitled
import java.util.* ; // task 1 starts abstract class student{ abstract void take_exam(); } class phdStudent extends student{ void take_exam(){ System.out.println("PHD student takes FINAL DEFENSE EXAM"); } } class gradStudent extends student{ void take_exam(){ System.out.println("Grad student takes WRITTEN PAPER EXAM"); System.out.println(" "); } } // task 1 ends // task 2 starts interface Movvable{ void moveUp(); void moveDown(); void moveLeft(); void moveRight(); } class movvablePoint implements Movvable{ int up=0, down=0, left=0, right=0; public void moveUp(){ System.out.println("Up is: " + ++up); } public void moveDown(){ System.out.println("Down is: " + ++down); } public void moveLeft(){ System.out.println("Left is: " + ++left); } public void moveRight(){ System.out.println("Right is: " + ++right); System.out.println(" "); } } class movvableCircle implements Movvable{ int up=0, down=0, left=0, right=0; public void moveUp(){ System.out.println("Up is: " + (up+=5)); } public void moveDown(){ System.out.println("Down is: " + (down+=5)); } public void moveLeft(){ System.out.println("Left is: " + (left+=5)); } public void moveRight(){ System.out.println("Right is: " + (right+=5)); System.out.println(" "); } } // task 2 ends // task 4 starts interface AdvancedArithmatic{ void divisorSum(int n); } class MyCalc implements AdvancedArithmatic{ int i, sum=0; public void divisorSum(int n){ for(i=1; i<=n; i++){ if(n%i == 0){ System.out.println("Divisor: "+ i); sum += i; } } System.out.println("Sum of divisors are: "+ sum); } } // task 4 ends //task 7 starts interface Account{ void getName(); void setName(); void getPass(); } interface Email{ void getOTP(); void setOTP(); void verifyEmail(); } class person implements Account, Email{ String name, pass, OTP, realOTP = "42060"; public void getName() { System.out.println("Enter name: "); Scanner sc = new Scanner(System.in); name = sc.nextLine(); } public void setName(){ System.out.println("The name is: "+ name); } public void getPass(){ System.out.println("Enter Password: "); Scanner sc1 = new Scanner(System.in); pass = sc1.nextLine(); } public void getOTP(){ System.out.println("Enter OTP: "); Scanner sc2 = new Scanner(System.in); OTP = sc2.nextLine(); } public void setOTP(){ System.out.println("Your OTP is: "+ OTP); if(OTP==realOTP){ System.out.println("OTP has matched"); } else { System.out.println("OTP didnt match"); } } public void verifyEmail(){ System.out.println("Your email is verified "); } } //task 7 ends public class Main { public static void main(String[] args) { //task 1 student st = new phdStudent(); st.take_exam(); student st2 = new gradStudent(); st2.take_exam(); //task 2 Movvable movc = new movvableCircle(); movc.moveUp(); movc.moveUp(); Movvable movp = new movvablePoint(); movp.moveUp(); //task 4 Scanner sc = new Scanner(System.in); System.out.println("Enter a number to get of its Divisors: "); int n = sc.nextInt(); AdvancedArithmatic ar = new MyCalc(); ar.divisorSum(n); // task 7 person p = new person(); p.getName(); p.setName(); p.getPass(); p.getOTP(); p.setOTP(); p.verifyEmail(); } }
Leave a Comment