Java Exercise 6: Custom Calculator | Java Practice Question

Поділитися
Вставка
  • Опубліковано 19 січ 2025

КОМЕНТАРІ • 374

  • @CodeWithHarry
    @CodeWithHarry  4 роки тому +111

    1:18 - Ye bhi ho jaata hai kabhi kabhi 😅🤦‍♂️

    • @piyush_tiwari
      @piyush_tiwari 4 роки тому +9

      Mere saath not responding hota hai 😂😂😂
      Edit: :O I am first replier even after refresh

    • @mohitchauhan7514
      @mohitchauhan7514 4 роки тому

      😂😂

    • @saahirrecords3062
      @saahirrecords3062 4 роки тому

      Sir plzz help me mere sath ek problem ho rha hai jb mai inspect mai jaa kar media use kr rha hu CSS mai toh sb shi hai jaise hi browser minimize krta hu or same width pr lata hu toh image kat jata hai height mai plzz insta pe v msg kya hu plzz sir I m totally confused kaise shi karu khi vi tutorial nhi mil rha app hi help kr skte hai

    • @sulectures2773
      @sulectures2773 4 роки тому

      Funny to see😅😅

    • @saahirrecords3062
      @saahirrecords3062 4 роки тому

      Plzzz repky

  • @09.arkodevmukherjee24
    @09.arkodevmukherjee24 4 роки тому +11

    6:31 I have seen every video of this java playlist and waiting for the next chapter

  • @hemangithakkar8280
    @hemangithakkar8280 3 роки тому +5

    I have watch whole playlist till this video a big thankyou to teach us Salute to u . U are great harry bhai

  • @pulkit8133
    @pulkit8133 2 місяці тому +1

    I am watching this playlist from the very beginning sir :)

  • @yogesh6210
    @yogesh6210 2 місяці тому +1

    Challenges are always accepted, cause I got a good teacher ❤

  • @14.8a.pratyushkanungo2
    @14.8a.pratyushkanungo2 4 роки тому +5

    THANK YOU! For making such a excellent course for free

  • @prathameshadawale8752
    @prathameshadawale8752 2 роки тому +2

    I have watching whole playlist .😍😍

  • @rhythmmotwani6710
    @rhythmmotwani6710 3 роки тому +1

    Challenge accepted 👍
    Mene abhi tak ki saari videos dekhi hai java ki 🥳

  • @royfamily9273
    @royfamily9273 2 роки тому

    Mene starting se yaha tak sare videos dekhe Harry Bhaiya.

  • @rahulkarmakar_india
    @rahulkarmakar_india 4 роки тому +8

    Hello Harry bhaiya, please make a video on "creating a Blogger template"

  • @illusionist7583
    @illusionist7583 4 роки тому +4

    you are my saviour in lockdowns

  • @yash_chutake
    @yash_chutake 3 роки тому

    Watching from video no 1... Java me Bhot maja arha..he..

  • @lifeturn7350
    @lifeturn7350 3 роки тому

    Maine ap ke sare vidio dhekhe hai bahut Maja sekhneko bhi Milla hame thank you

  • @d_10_devanshshrivastava28
    @d_10_devanshshrivastava28 2 роки тому

    Challenege Accepted & I have watched the videos from starting...

  • @royfamily9273
    @royfamily9273 2 роки тому

    Challenge Accepted.
    Thanks Harry Bhaiya

  • @letsgetcopyright2603
    @letsgetcopyright2603 4 роки тому

    Upload all series for everyone .
    Bhai ma pakistani hon but ek na ek din ma ap sy milny zaroor aayon ga.
    Mera nam yad rakhna ma atleast 10 sal bad milon ga.
    Love you bro jo kr rahy ho karty raho.
    OR ye comment ma ap ki har video ma kron ga kisi ma tu reply aay ga na..

  • @adityakrsna9640
    @adityakrsna9640 4 роки тому +2

    Sir pls upload video on C++, Android Development and Java in simultaneously.
    So that there will be Balance between students learning Java, C++,etc.
    Pls make more videos on Machine Learning and Artificial intelligence 🙏

  • @NileshPanchal-nx4pw
    @NileshPanchal-nx4pw 2 роки тому

    Learnt all videos from brginning.

  • @mayankbalyan6711
    @mayankbalyan6711 4 роки тому +1

    Sir congrats for 1 million

  • @animationmakeranonymous3215
    @animationmakeranonymous3215 4 роки тому +1

    Sir you are great helping so much in learning computer languages

  • @Zeno0981
    @Zeno0981 2 роки тому +1

    maine dekh rha suru se
    and challenge accepted

  • @aayushjain6650
    @aayushjain6650 4 роки тому +1

    First like and view from my side .... yaaaay

  • @SaM-gq8cf
    @SaM-gq8cf Рік тому +2

    Exercise 6 : Custom Calculator
    CODE - - -
    import java.util.Scanner;
    class Calculator2 extends Exception {
    public Calculator2(String message) {
    super(message);
    }
    @Override
    public String toString() {
    return "Invalid input Exception";
    }
    // @Override
    // public String getMessage() {
    // return "Invalid input Exception";
    // }
    }
    public class CalculatorException {
    public static int add(int a, int b) throws Calculator2 {
    if (a > 10000 || b > 10000) {
    throw new Calculator2("Max input Exception: input should not be greater than 10000");
    }
    return a + b;
    }
    public static int multiply(int a, int b) throws Calculator2 {
    if (a > 7000 || b > 7000) {
    throw new Calculator2("Max input Exception: input should not be greater than 7000");
    }
    return a * b;
    }
    public static float divide(int a, int b) throws Calculator2 {
    if (a > 7000 || b > 7000) {
    throw new Calculator2("Max input Exception: input should not be greater than 7000");
    }
    if (b == 0) {
    throw new ArithmeticException("Cannot divide by zero Exception");
    }
    return (float) a / b;
    }
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("Choose between the following options:");
    System.out.println("1. Addition");
    System.out.println("2. Multiplication");
    System.out.println("3. Division");
    int ch = sc.nextInt();
    switch (ch) {
    case 1:
    System.out.println("Enter number 1 and number 2:");
    int a1 = sc.nextInt();
    int b1 = sc.nextInt();
    try {
    int res = add(a1, b1);
    System.out.println("The result is " + res);
    } catch (Calculator2 e) {
    System.out.println(e.getMessage());
    }
    break;
    case 2:
    System.out.println("Enter number 1 and number 2:");
    int a2 = sc.nextInt();
    int b2 = sc.nextInt();
    try {
    int res = multiply(a2, b2);
    System.out.println("The result is " + res);
    } catch (Calculator2 e) {
    System.out.println(e.getMessage());
    }
    break;
    case 3:
    System.out.println("Enter number 1 and number 2:");
    int a3 = sc.nextInt();
    int b3 = sc.nextInt();
    try {
    float res = divide(a3, b3);
    System.out.println("The result is " + res);
    } catch (Calculator2 | ArithmeticException e) {
    System.out.println(e.getMessage());
    }
    break;
    default:
    System.out.println("Invalid option");
    break;
    }
    sc.close(); // It closes the Scanner object(it's a good practice).
    }
    }

  • @piyush_tiwari
    @piyush_tiwari 4 роки тому +3

    Waiting for a ❤ from code with harry from months

  • @infinitestellar109
    @infinitestellar109 4 роки тому

    6:31 I have seen each & every video of this java playlist

  • @TheExamCentral
    @TheExamCentral 2 роки тому

    shuru se abhi takk saare videos maine dekhe haain

  • @pavannangare-patil3658
    @pavannangare-patil3658 4 роки тому +1

    Lots of Love💖
    Harry bhaii🔥🔥

  • @MANISH74506
    @MANISH74506 4 роки тому +2

    Very helpful bhai...

  • @gurudwarasinghsabhachhatarpur
    @gurudwarasinghsabhachhatarpur 2 роки тому +1

    Challenge accepted
    I have watched the whole course from beginning and really liking ig

  • @WINDOWS-sv3er
    @WINDOWS-sv3er 4 роки тому

    One of the best channel 👍

  • @murlidhartalwani4807
    @murlidhartalwani4807 4 роки тому +2

    Harry Bhai Please Make a Tutorial On Open Cv in Python

  • @ambikakumari9688
    @ambikakumari9688 3 роки тому

    Hello sir,
    I'm watching your video from starting till now and I will complete this playlist. (03 Feb 2022)

  • @KungFuAndaa
    @KungFuAndaa 4 місяці тому +1

    package fundamentals;
    import java.util.Scanner;
    class InvalidInputException extends Exception{

    public String toString() {
    return "InvalidInputException, enter a valid operator";
    }
    }
    class MaxInputException extends Exception{

    public String toString() {
    return "MaxInputException, enter a valid exception";
    }
    }
    class MaxMultiException extends Exception{

    public String toString() {
    return "MaxMultiException, enter a valid exception";
    }
    }
    class DivideByZeroException extends Exception{

    public String toString() {
    return "DivideByZeroException, enter a valid exception";
    }
    }
    public class CustomCalculator {
    public static void main(String[] args) throws MaxMultiException, InvalidInputException, DivideByZeroException, MaxInputException {

    Scanner sc = new Scanner(System.in);
    System.out.println("Enter value a:");
    int a= sc.nextInt();
    System.out.println("Enter value b:");
    int b= sc.nextInt();
    System.out.print("Enter value of operator:(+, -, *, /):");
    char operator = sc.next().charAt(0);

    if(operator != '+' && operator != '-' && operator != '*' && operator != '/' ) {
    throw new InvalidInputException();
    }

    else if(b==0 && operator== '/') {
    throw new DivideByZeroException();
    }

    else if(a>100000 || b> 100000) {
    throw new MaxInputException();
    }

    else if((a * b)>7000 ) {
    throw new MaxMultiException();
    }

    else {
    switch(operator) {
    case '+': System.out.println(a + b); break;
    case '-': System.out.println(a - b); break;
    case '*': System.out.println(a * b); break;
    case '/': System.out.println(a / b); break;
    default: System.out.println("Default Case");
    }
    System.out.println("Execution Completed!");



    }
    }
    }

  • @rajkamalrajarshi4349
    @rajkamalrajarshi4349 3 роки тому

    i have seen each and every video of this playlist thankyouu sir

  • @yuvishko
    @yuvishko 4 роки тому +1

    Thanx bro you really help me to reach my goals 😊☺️

  • @TechnicalVandar
    @TechnicalVandar 4 роки тому +3

    import java.util.Scanner;

    public class calculator {

    public static void main(String[] args) {

    float a, b, res;
    char choice, ch;
    Scanner S = new Scanner(System.in);

    do {
    // prepare menu for the user to see multiple operations.
    System.out.println("Main Menu: ");
    System.out.println(" 1 Addition");
    System.out.println(" 2 Subtraction");
    System.out.println(" 3 Division");
    System.out.println(" 4 Multiplication");
    System.out.println(" 5 Exit");

    // enter the choice
    System.out.print("Enter your choice: ");

    choice = S.next().charAt(0);

    switch (choice) {
    case '1':
    System.out.print("Enter two numbers: ");
    a = S.nextFloat();
    b = S.nextFloat();
    res = a + b;
    System.out.println("Result: " + res);
    break;

    case '2':
    System.out.print("Enter two numbers: ");
    a = S.nextFloat();
    b = S.nextFloat();
    res = a - b;
    System.out.println("Result: " + res);
    break;

    case '3':
    System.out.println("Enter two numbers: ");
    a = S.nextFloat();
    b = S.nextFloat();
    res = a / b;
    System.out.println("Result: " + res);
    break;

    case '4':
    System.out.print("Enter two numbers: ");
    a = S.nextFloat();
    b = S.nextFloat();
    res = a * b;
    System.out.println("Result : " + res);
    break;

    case '5':
    System.exit(0);
    break;
    default:
    System.out.println("Invalid Choice");
    break;
    }
    } while (choice != 5);
    }
    }

    • @TechnicalVandar
      @TechnicalVandar 4 роки тому

      @@SadmanSakib2001 just for simple calculation

  • @aymanmomin432
    @aymanmomin432 4 роки тому +2

    challenge accepted and completed!!!

  • @rohanbiswas9194
    @rohanbiswas9194 3 роки тому

    I am with your Series 1st to last

  • @vatsalpare6235
    @vatsalpare6235 4 роки тому +1

    Bhaiya please make a video on how to become a ethical hacker Or cyber security expert.

  • @aInvincibleProgramer789
    @aInvincibleProgramer789 2 роки тому

    ✔ done thanxx sir 🥰

  • @aahutoshdwivedi6154
    @aahutoshdwivedi6154 Рік тому

    Thank you sir ji

  • @subha2184
    @subha2184 2 роки тому +1

    Solution of this question using simple oops concepts.
    class InputException extends Exception{
    @Override
    public String toString()
    {
    return "Invalid input";
    }
    }
    class MultipleException extends Exception
    {
    @Override
    public String toString()
    {
    return "Invalid input for multiplication";
    }
    }
    class DivisionException extends Exception
    {
    @Override
    public String toString() {
    return "Can not divide by zero";
    }
    }
    class Calculator{
    public void addition(double a, double b)
    {
    double c = 0;
    try {
    c = a + b;
    if (a == 8 || b==8 || a==9 || b==9 || a>100000 || b>100000) {
    throw new InputException();
    }
    else
    System.out.println("Result after addition is: " +c);
    } catch (InputException e) {
    System.out.println(e.toString());
    }
    }
    public void subtraction(double a, double b)
    {
    double c = 0;
    try {
    c = a - b;
    if (a == 8 || b==8 || a==9 || b==9 || a>100000 || b>100000) {
    throw new InputException();
    }
    else
    System.out.println("Result after subtraction is:" +c);
    } catch (InputException e) {
    System.out.println(e.toString());
    }
    }
    public void Multiplication(double a, double b)
    {
    double c = 0;
    try {
    c = a*b;
    if (a == 8 || b==8 || a==9 || b==9) {
    throw new InputException();
    } else if (a>7000 || b>7000 )
    {
    throw new MultipleException();
    } else
    System.out.println("Result after multiplication is:" +c);
    } catch (InputException e) {
    System.out.println(e.toString());
    }
    catch (MultipleException e){
    System.out.println(e.toString());
    }
    }
    public void Division(double a, double b)
    {
    double c = 0;
    try {
    c = a/b;
    if (a == 8 || b==8 || a==9 || b==9 || a>100000 || b>100000) {
    throw new InputException();
    } else if (a==0 || b==0)
    {
    throw new DivisionException();
    } else
    System.out.println("Result after division is:" +c);
    } catch (InputException e) {
    System.out.println(e.toString());
    }
    catch (DivisionException e){
    System.out.println(e.toString());
    }
    }
    }
    public class Excercise_6 {
    public static void main(String[] args)
    {
    Calculator obj=new Calculator();
    obj.addition(1,100000);
    obj.subtraction(7,100000);
    obj.Multiplication(5,15);
    obj.Division(16,3);
    }
    }

  • @Vikas-vy4vs
    @Vikas-vy4vs 4 роки тому +1

    How much syllabus are left in this course? 4months go.

  • @justmeeeeeee
    @justmeeeeeee 2 роки тому

    Plz. Make a videos for java advance syllabus. In details

  • @HiTech1203
    @HiTech1203 4 роки тому +2

    DBMS crash course please as fast as possible

  • @gautambirhade78
    @gautambirhade78 4 роки тому +1

    Sir please suggest me a nice budget laptop for web/app developing

  • @inayasingh2680
    @inayasingh2680 4 роки тому +1

    Bhai plz upload java EE videos also 🙏🙏🙏🙏🙏🙏🙏

  • @HatakeKakashi10
    @HatakeKakashi10 4 роки тому +1

    sir sql language me video banao na pls

  • @yashsimra6090
    @yashsimra6090 3 роки тому

    maza ara hai harry sir

  • @masti983
    @masti983 4 роки тому

    Harry bhai digital marketing par video bano

  • @rishav6237
    @rishav6237 4 роки тому +2

    I'm in BA English
    Can learning to code will help me?
    And can I learn web development without maths bc I'm very bad at maths.

  • @satvikmittal4487
    @satvikmittal4487 4 роки тому +32

    Accepted
    //Made by Satvik Mittal
    //Purely made in VS Code
    import java.util.InputMismatchException;
    import java.util.Scanner;
    class InvalidInputException extends InputMismatchException{
    @Override
    public String toString() {
    return "Not a valid operation";
    }
    @Override
    public String getMessage() {
    return "Pls enter a valid operation";
    }
    }
    class ZeroException extends ArithmeticException{
    @Override
    public String toString() {
    return "Cannot divide by 0";
    }
    @Override
    public String getMessage() {
    return "Enter a number other than 0";
    }
    }
    class MaxInputException extends InputMismatchException{
    @Override
    public String toString() {
    return "Number can't exceed 100000";
    }
    @Override
    public String getMessage() {
    return "Pls enter a number 7000";
    }
    @Override
    public String getMessage() {
    return "Pls enter a number

  • @shaileshhacker
    @shaileshhacker 3 роки тому

    Thank You

  • @RaghavRoy-vo4jd
    @RaghavRoy-vo4jd 4 роки тому

    plz one vedios harry bahi for commerse students to how to become a software engineer plz make a vedio harry bahi plz dont ignore.

  • @vatsalyagaur24
    @vatsalyagaur24 4 роки тому +1

    Nice 👍

  • @Sahib0_0
    @Sahib0_0 4 роки тому +1

    Bhai 1m hone wale hai😁😁

  • @gkanything9567
    @gkanything9567 3 роки тому

    Thanks a lot sir 🔥 🔥 🔥

  • @codewithsajal746
    @codewithsajal746 4 роки тому

    Accounting ka video bhi banao plz🙏🏻🙏🏻

  • @sabyasachidas1970
    @sabyasachidas1970 4 роки тому

    Herry bhi Arduino tutorial series per video banao

  • @hwaiting3573
    @hwaiting3573 3 роки тому

    Challenge Accepted. I watched all till now

  • @kishanmadlani1391
    @kishanmadlani1391 Рік тому

    DONE BROTHER

  • @Creation_times
    @Creation_times 4 роки тому

    Sir ji data structures kab tak khatam hoga??
    I mean abhi main wo kar raha hu aur exam aane vale hain to about kitna baki hoga ??

  • @mdehteshamurrahman5306
    @mdehteshamurrahman5306 Рік тому

    challenge accepted and also completed in one go

  • @Arceus948
    @Arceus948 4 роки тому +1

    Sir how many more topics are left?? Pls reply 😭😭😭😭😭😭🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @aaradhnagorgeousvlogsworld3967
    @aaradhnagorgeousvlogsworld3967 4 роки тому

    DracWound has accepted it
    Challenge accepted
    I am watching this play list's videos from starting

  • @mdshahabuddin1010
    @mdshahabuddin1010 4 роки тому

    Sir Advance Java bhi karaoge

  • @Victor-ev3vu
    @Victor-ev3vu 4 роки тому +1

    Please make tutorial on kivy after this one

    • @pkanil8374
      @pkanil8374 4 роки тому

      Yeah, I want this , Please bhai make a playlist on this

  • @sagarpaliwal6669
    @sagarpaliwal6669 4 роки тому +1

    can you help me ..??????????? in my console CORS policy in chrome browser error occur ..can you help me how to overcome it ..or may suggest a tutorial video for CORS policy ...

  • @zeeshanali4502
    @zeeshanali4502 Рік тому

    did it
    thank s

  • @AbhaySingh-sq9vx
    @AbhaySingh-sq9vx 3 роки тому +10

    /*Hello Harry sir,
    I am watching this course from starting,
    I saw this video today and accept the challenge and here is my answer*/
    package com.masaaledaarCalculator;
    import java.util.Scanner;
    class InvalidInput extends Exception{
    @Override
    public String toString(){
    return "Operator is invalid";
    }
    }
    class MaxInputException extends Exception{
    @Override
    public String toString(){
    return "Input can't be greater than 1 lakh";
    }
    }
    class MaxMultiplierException extends Exception{
    @Override
    public String toString() {
    return "Input can't be greater than 7 thousand in multiplication";
    }
    }
    public class code extends Exception{
    public static void operatorCheck(String opr) throws InvalidInput {
    if (opr.equals("+") || opr.equals("-") || opr.equals("*") || opr.equals("/")) return;
    throw new InvalidInput();
    }
    public static double add(int x,int y) throws MaxInputException {
    if (x>100000||y>100000) throw new MaxInputException();
    System.out.println("The value of "+x+" + "+y+" is : ");
    return x+y;
    }
    public static double subtract(int x,int y) throws MaxInputException {
    if (x>100000||y>100000) throw new MaxInputException();
    System.out.println("The value of "+x+" - "+y+" is : ");
    return x-y;
    }
    public static double multiply(int x,int y) throws MaxMultiplierException {
    if (x>7000||y>7000) throw new MaxMultiplierException();
    System.out.println("The value of "+x+" * "+y+" is : ");
    return x*y;
    }
    public static double divide(int x,int y) throws MaxInputException,ArithmeticException {
    if (x>100000||y>100000) throw new MaxInputException();
    System.out.println("The value of "+x+" / "+y+" is : ");
    return x/y;
    }
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println("Enter the operator(only +,-,*,/ are allowed): ");
    String opr = sc.next();
    try {
    operatorCheck(opr);
    }
    catch (Exception e){
    System.out.println(e);
    return;
    }
    System.out.println("Enter the first number : ");
    int x = sc.nextInt();
    System.out.println("Enter the second number : ");
    int y = sc.nextInt();
    if (opr.equals("+")){
    try{
    System.out.println(add(x,y));
    }
    catch (Exception e){
    System.out.println(e);
    }
    }
    else if (opr.equals("-")){
    try{
    System.out.println(subtract(x,y));
    }
    catch (Exception e){
    System.out.println(e);
    }
    }
    else if (opr.equals("*")){
    try{
    System.out.println(multiply(x,y));
    }
    catch (Exception e){
    System.out.println(e);
    }
    }
    else {
    try{
    System.out.println(divide(x,y));
    }
    catch (Exception e){
    System.out.println(e);
    }
    }
    }
    }
    /* Thank you Harry sir for providing such an amazing course at 0 cost;
    Hoping that you will reply soon and give me a shoutout*/

  • @salmanrajpoot6822
    @salmanrajpoot6822 Рік тому +1

    Challenge Excepted
    And Alhamdulillah done
    Allah ka fazal se
    package com.companey;
    import java.util.Scanner;
    import java.util.concurrent.ExecutionException;
    class InvalidInput extends Exception{
    @Override
    public String toString(){
    return "Invalid input exception / Exeption";
    }
    @Override
    public String getMessage(){
    return "Why you are entering 8 , 9 ";
    }
    }
    class MaxInput extends Exception{
    @Override
    public String toString(){
    return "Max Input greater then, 100000";
    }
    @Override
    public String getMessage(){
    return "why you are using greater than 1lac value";
    }
    }
    class MaxMultiplierReached extends Exception{
    @Override
    public String toString(){
    return " Max Multiplier Reached";
    }
    @Override
    public String getMessage(){
    return "why you are using above value of 7000";
    }
    }
    class CantDivByZero extends Exception{
    @Override
    public String toString(){
    return "Divided by / Zero Exception";
    }
    @Override
    public String getMessage(){
    return "Why your are entering Zero for division!";
    }
    }
    class DivLaterValue extends Exception{
    @Override
    public String toString(){
    return "dive by value is big";
    }
    @Override
    public String getMessage(){
    return "why your are entering div by value in here";
    }
    }
    class CostumeCalculator{
    public void add(int a, int b) /*throws MaxInput, InvalidInput*/ {
    try {
    if (a

  • @utkarshsalaria3952
    @utkarshsalaria3952 3 роки тому +13

    Note: Here MaxMultiplierReachedException occurs if the result of multiplication reached above 700000. Which is different from the one asked in the question, only done so to make it look somewhat realistic.
    import java.util.Scanner;
    class MaxInputException extends Exception{
    @Override
    public String toString(){
    return "Max Input Exception occured: Inputs must be less or equal to 100000";
    }

    @Override
    public String getMessage(){
    return "Max Input Exception occured: Inputs must be less or equal to 100000";
    }
    }
    class InvalidInputException extends Exception{
    @Override
    public String toString(){
    return "Invalid Input Exception occured: Operand Specified must be one of them: +, -, *, /";
    }

    @Override
    public String getMessage(){
    return "Invalid Input Exception occured: Operand Specified must be one of them: +, -, *, /";
    }
    }
    class DivideByZeroException extends Exception{
    @Override
    public String toString(){
    return "Divide By Zero Exception occured: Denominator of the division can not be Zero(0)";
    }

    @Override
    public String getMessage(){
    return "Divide By Zero Exception occured: Denominator of the division can not be Zero(0)";
    }
    }
    class MaxMultiplierReachedException extends Exception{
    @Override
    public String toString(){
    return "Max Multiplier Reached Exception occured: The result of multiplication reached above 700000";
    }

    @Override
    public String getMessage(){
    return "Max Multiplier Reached Exception occured: The result of multiplication reached above 700000";
    }
    }
    class CalculatorUsingCustomExceptions{

    public static int div(int x,int y) throws DivideByZeroException{
    if(y==0){
    throw new DivideByZeroException();
    }
    return x/y;
    }

    public static int mul(int x,int y) throws MaxMultiplierReachedException{
    int result=x*y;
    if(result>700000){
    throw new MaxMultiplierReachedException();
    }
    return result;
    }

    public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    String operand;
    int a;
    int b;
    while(true){
    System.out.println("Enter first number:");
    a=sc.nextInt();

    System.out.println("Enter second number:");
    b=sc.nextInt();
    if(a>100000||b>100000){
    try{
    throw new MaxInputException();
    }catch(Exception e){
    System.out.println(e);
    continue;
    }
    }

    System.out.println("Press + for Addition
    Press - for Subtraction
    Press / for Division
    Press * for Multiplication
    press q to quit");
    operand=sc.next();



    switch(operand){
    case "+":{
    System.out.println("Sum="+(a+b));
    break;
    }
    case "-":{
    System.out.println("substraction="+(a-b));
    break;
    }
    case "*":{
    try{
    System.out.println("multplication="+mul(a,b));
    }catch(Exception e){
    System.out.println(e);
    }
    break;
    }
    case "/":{
    try{
    System.out.println("Division="+div(a,b));
    }catch(Exception e){
    System.out.println(e);
    }
    break;
    }
    case "q":case "Q":{
    System.exit(0);
    }
    default:{
    try{
    throw new InvalidInputException();
    }catch(Exception e){
    System.out.println(e);
    }
    break;
    }

    }
    }

    }

    }

  • @rajbannasa7662
    @rajbannasa7662 4 роки тому

    thanku so much sirrr

  • @rajatchaurasia3578
    @rajatchaurasia3578 3 роки тому +1

    Present sir ❤👌🏻❤👌🏻❤👌🏻

  • @gamerxrobin1323
    @gamerxrobin1323 Рік тому

    why should i use try-catch when i can create this code by simple if else ???

  • @shivanshutyagi83
    @shivanshutyagi83 4 роки тому

    Harry bhai 👋👋

  • @ushabagal5479
    @ushabagal5479 4 роки тому +1

    Hi bro, if learn python programming 3.7.1 version it's ok or not .

  • @AdeshSinghchandel
    @AdeshSinghchandel 4 роки тому

    Can you please make h series on Vue.js tutorial...

  • @mohitchauhan7514
    @mohitchauhan7514 4 роки тому

    Bhai
    Android development course apke channel kar complete h ya nahi

  • @stayforbidden9736
    @stayforbidden9736 4 роки тому

    harry bhai ek request hai ek video banaiye jquery mobile par mene youtube par bahut sari video dekhi par jquery mobile ki video hindi me sahi tarike se nahi mili.

  • @RajYadav-im6cb
    @RajYadav-im6cb 4 роки тому +1

    Sir I want to ask you .why the Indian web developers are not developing app like WhatsApp in such privacy concern issues.
    Sir please answer it .

  • @WINDOWS-sv3er
    @WINDOWS-sv3er 4 роки тому +1

    Students comment below ❤️🙏👍

  • @RajYadav-im6cb
    @RajYadav-im6cb 4 роки тому

    Sir you have all the knowledge and resources
    So why can’t you make app like WhatsApp
    Chat app for India .is it impossible for you to do that

  • @paradiseonearth9755
    @paradiseonearth9755 3 роки тому

    I saw all from beginning

  • @Neha-il3xi
    @Neha-il3xi 4 роки тому +1

    Accepted

  • @pranshuparashar4769
    @pranshuparashar4769 4 роки тому

    Gurudev please continue DS algo series...

  • @yashbhatnagar1325
    @yashbhatnagar1325 4 роки тому +1

    CHALLENGE ACCEPTED and COMPLETED.

  • @ashishpal9176
    @ashishpal9176 2 роки тому +1

    //Custum calculator as per your instructions
    class InvalidInputException extends Exception{
    @Override
    public String toString() {
    return "Cannot divide 8 and 9";
    }
    @Override
    public String getMessage() {
    return "I am get message";
    }
    }
    class CannotDivideZeroException extends Exception{
    @Override
    public String toString() {
    return "Cannot divide by zero";
    }
    @Override
    public String getMessage() {
    return "I am get message";
    }
    }
    class MaxInputException extends Exception{
    @Override
    public String toString() {
    return "Your input is greater than 1000 not allowed";
    }
    @Override
    public String getMessage() {
    return super.getMessage();
    }
    }
    class MaxMultiplyReached extends Exception{
    @Override
    public String getMessage() {
    return "Not allowed of any multiplication greater than 7000";
    }
    }
    class custumCalculator{
    double add(double a,double b) throws InvalidInputException,MaxInputException{
    if(a>1000||b>1000){
    throw new MaxInputException();
    }
    if(a==8 || b==9){
    throw new InvalidInputException();
    }
    return a+b;
    }
    double subtract(double a,double b) throws MaxInputException {
    if(a>1000||b>1000){
    throw new MaxInputException();
    }
    return a-b;
    }
    double multiply(double a,double b)throws MaxInputException,MaxMultiplyReached{
    if(a>7000||b>7000){
    throw new MaxMultiplyReached();
    }
    if(a>1000||b>1000){
    throw new MaxInputException();
    }
    return a*b;
    }
    double divide(double a,double b) throws CannotDivideZeroException,MaxInputException{
    if(a>1000||b>1000){
    throw new MaxInputException();
    }
    if(b==0){
    throw new CannotDivideZeroException();
    }
    return a/b;
    }
    }
    public class Custum_calculator {
    public static void main(String[] args) throws InvalidInputException,CannotDivideZeroException,MaxInputException,MaxMultiplyReached {
    custumCalculator cc=new custumCalculator();
    // cc.add(8,9);
    // cc.divide(8,1200);
    //cc.divide(32,0);
    cc.multiply(600,7001);
    }
    }

  • @sujitroy3077
    @sujitroy3077 4 роки тому

    Bhai app bolethe ki stock market pe series laoge

  • @agamghotra8619
    @agamghotra8619 4 роки тому +1

    package Projects.Projects;
    import java.util.*;
    class MaxMultiplierException extends Exception {
    public String toString() {
    return super.toString() + " Input Greater than 7000";
    }
    public String getMessage() {
    return super.getMessage() + " Input Greater than 7000";
    }
    }
    public class Custom_Calculator {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    /*
    * You have to create a custom calculator with the following operations :
    * 1. × Multiplication
    * 2. ÷ Division
    * 3. + Addition
    * 4. - Subtraction
    * which throws the following exceptions :
    * 1. Invalid Input Exception
    * 2. Cannot divide by 0 exception
    * 3. MaxInputException if any input is greater than 1000
    * 4. MaxMultiplier Exception - Don''t allow any multiplication input to be greater than 7000
    * */
    System.out.println("\t\t\t\tCUSTOM CALCULATOR
    ");
    System.out.println("The operations This calculator can perform are : ");
    System.out.println("1. (A)ddition (+)");
    System.out.println("2. (S)ubtraction (-)");
    System.out.println("3. (M)ultiplication(×)");
    System.out.println("4. (D)ivision (÷)");
    System.out.println("5. (E)xit
    ");
    char c = ' ';
    while(c != 'e' && c != 'E') {
    System.out.println("Enter the First Alphabet of the operation you want to perform : ");
    c = sc.next().charAt(0);
    System.out.println();
    switch(c){
    case 'A' :
    case 'a' :
    System.out.println("Enter the total number of figures for which you want the sum : ");
    int a;
    try {
    a = sc.nextInt();
    }
    catch(InputMismatchException ime) {
    System.out.println("There was an Error.");
    a = sc.nextInt();
    }
    double[] arr = new double[a];
    for(int x = 0; x < a ;x++) {
    System.out.println("Enter a number : ");
    try {
    arr[x] = sc.nextDouble();
    }
    catch(InputMismatchException Ime) {
    System.out.println("There was an error.");
    System.out.println("Enter a number : ");
    try {
    arr[x] = sc.nextDouble();
    }
    catch(InputMismatchException IME) {
    System.out.println("There was an error.");
    System.out.println("Enter a number : ");
    arr[x] = sc.nextDouble();
    }
    }
    }
    double sum = 0;
    for(int x = 0; x < a; x++) {
    sum += arr[x];
    }
    System.out.print("Sum of " );
    for(int x = 0;x

  • @vlogwithabhishek3121
    @vlogwithabhishek3121 4 роки тому +2

    Harry Bhai DSA k play list me video dalo I have already finished tree insertion and deletion.....but few topics are still remaining to upload!
    Bye the way thanks for all your struggles in making playlist DSA playlist 🔥

  • @pulkitpareek
    @pulkitpareek 3 роки тому

    shuru se abhi tak saare video dekhe hain

  • @avishchoudhary6732
    @avishchoudhary6732 4 роки тому +1

    //here is the answer:
    //before main method-
    import java.util.Scanner;
    class divide_by_zero extends Exception{
    @Override
    public String getMessage() {
    return "Suggestion:Please select any other number";
    }
    @Override
    public String toString() {
    return "Error:The divisor given is zero";
    }
    }
    class invalid_input_error extends Exception{
    @Override
    public String getMessage() {
    return "Suggestion:Please choose funtion among->
    -
    +
    *
    /";
    }
    @Override
    public String toString() {
    return "Error:Invalid function entered";
    }
    }
    class value_limit_reached extends Exception{
    @Override
    public String toString() {
    return "Error:Value can not be larger than 100000";
    }
    @Override
    public String getMessage() {
    return "Suggestion:Please enter value less 100000";
    }
    }
    class multilayer_limit_reached extends Exception{
    @Override
    public String toString() {
    return "Error:Multiplication value can not be larger than 7000";}
    @Override
    public String getMessage() {
    return "Suggestion:Please select value less than 7000";
    }
    }
    // after main method..
    System.out.println("The Calculator:Exercise 6");
    System.out.println("Type:
    + for add
    - for subtract
    * for multiply
    / for divide");
    Scanner input=new Scanner(System.in);
    //funtion
    System.out.println("Enter the function");
    String function=input.next();
    //numerical value
    System.out.println("enter number 1");
    int num1=input.nextInt();
    System.out.println("enter number 2");
    int num2=input.nextInt();
    switch (function){
    case "/" -> {
    if (num2 == 0) {try{
    throw new divide_by_zero();}
    catch (Exception a){
    System.out.println(a.toString());
    System.out.println(a.getMessage());
    }
    }
    else {System.out.println("the result is " + (num1 / num2));}
    }
    case "+"-> {
    if (num1>=100000 | num2>=100000){
    try{
    throw new value_limit_reached();
    }
    catch (Exception a){
    System.out.println(a.toString());
    System.out.println(a.getMessage());
    }
    }
    else {System.out.println("the result is " + (num1 + num2));}
    }
    case "-"->{
    if (num1>=100001 | num2>=100001){try{
    throw new value_limit_reached();}
    catch (Exception a){
    System.out.println(a.toString());
    System.out.println(a.getMessage());
    }
    }
    else {System.out.println("the result is " + (num1 - num2));}
    }
    case "*"->{if (num1>=7001 | num2>=7001){
    try{
    throw new multilayer_limit_reached();
    }
    catch (Exception a){
    System.out.println(a.toString());
    System.out.println(a.getMessage());
    }
    }
    else {System.out.println("the result is " + (num1 * num2));}}
    default -> {try {
    throw new invalid_input_error();
    }
    catch (Exception a){
    System.out.println(a.toString());
    System.out.println(a.getMessage());
    }
    } }
    //thnx for this course and second answer!!!!!!

  • @AdityaRajRA
    @AdityaRajRA 4 роки тому

    sir jii data structure wali playlist complete kr do plzzz...

  • @harsimran.27
    @harsimran.27 4 роки тому

    Done....

  • @yashsimra6090
    @yashsimra6090 3 роки тому

    kya java ki tutorial over ho gai hai 113 video par?

  • @codewithsajal746
    @codewithsajal746 4 роки тому

    Bro plzzz accounting padhao 🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @ravikanttiwari6623
    @ravikanttiwari6623 4 роки тому

    Sir when we will get full android development playlist

  • @joybrar9024
    @joybrar9024 3 роки тому

    Challenge Accepted sir !!

  • @shubamrazdan8655
    @shubamrazdan8655 3 роки тому

    I have done this problem