FOR JAVA. ADD TRY AND CATCH BLOCK TO THESE METHODS  import java.util.Scanner;   public class Company {   privateintage; privateStringname; privateStringheight;     publicCompany(intage,Stringname,Stringheight){ super(); this.age=age; this.name=name; this.height=height; } publicintgetAge(){ returnage; } publicvoidsetAge(intage){ this.age=age; } publicStringgetName(){ returnname; } publicvoidsetName(Stringname){ this.name=name; } publicStringgetHeight(){ returnheight; } publicvoidsetHeight(Stringheight){ this.height=height; } @Override publicStringtoString(){ return"Company [age="+age+", name="+name+", height="+height+"]";   }   publicstaticvoidmain(String[]args){   Companyc1=newCompany(21,"Kıvanç","1.84"); Companyc2=newCompany(40,"Ali","1.90"); Companyc3=newCompany(30,"Veli","1.78"); Companyc4=newCompany(29,"Burak","1.75"); Companyc5=newCompany(70,"Selçuk","1.85");       System.out.println(c1); c1.setAge(44); System.out.println(c1);   c2.setHeight("1.68"); System.out.println(c2);   c3.setName("Ayşe"); System.out.println(c3);   System.out.println(c4.getAge());   System.out.println(c5.getName());         publicvoidcountTotalEmp(intbranch1,intbranch2,intbranch3){       inttotalEmp=branch1+branch2+branch3;       System.out.print("Total number of employees: "+totalEmp);     }     //method for calculate the total income     publicvoidcountTotalIncome(intbranch1,intbranch2,intbranch3){       inttotalIncome=branch1+branch2+branch3;       System.out.print("Total company income: "+totalIncome);     }     //method for calculate the total tax     publicvoidcountTotalTax(intbranch1,intbranch2,intbranch3){       inttotalTax=branch1+branch2+branch3;       System.out.print("Total company tax: "+totalTax);     }     //method for calculate the total weekely worked hours     publicvoidcountTotalWeeklyHours(intbranch1,intbranch2,intbranch3){       inttotalHours=branch1+branch2+branch3;       System.out.print("Total weekly worked hours: "+totalHours);     }     //method to calculate the total expenditure     publicvoidcountTotalExpenditure(intbranch1,intbranch2,intbranch3){       inttotalExp=branch1+branch2+branch3;       System.out.print("Total company expenditure: "+totalExp);     }         }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

FOR JAVA. ADD TRY AND CATCH BLOCK TO THESE METHODS 

import java.util.Scanner;

 

public class Company {

 

privateintage;

privateStringname;

privateStringheight;

 

 

publicCompany(intage,Stringname,Stringheight){

super();

this.age=age;

this.name=name;

this.height=height;

}

publicintgetAge(){

returnage;

}

publicvoidsetAge(intage){

this.age=age;

}

publicStringgetName(){

returnname;

}

publicvoidsetName(Stringname){

this.name=name;

}

publicStringgetHeight(){

returnheight;

}

publicvoidsetHeight(Stringheight){

this.height=height;

}

@Override

publicStringtoString(){

return"Company [age="+age+", name="+name+", height="+height+"]";

 

}

 

publicstaticvoidmain(String[]args){

 

Companyc1=newCompany(21,"Kıvanç","1.84");

Companyc2=newCompany(40,"Ali","1.90");

Companyc3=newCompany(30,"Veli","1.78");

Companyc4=newCompany(29,"Burak","1.75");

Companyc5=newCompany(70,"Selçuk","1.85");

 

 

 

System.out.println(c1);

c1.setAge(44);

System.out.println(c1);

 

c2.setHeight("1.68");

System.out.println(c2);

 

c3.setName("Ayşe");

System.out.println(c3);

 

System.out.println(c4.getAge());

 

System.out.println(c5.getName());

 

 

    publicvoidcountTotalEmp(intbranch1,intbranch2,intbranch3){

      inttotalEmp=branch1+branch2+branch3;

      System.out.print("Total number of employees: "+totalEmp);

    }

    //method for calculate the total income

    publicvoidcountTotalIncome(intbranch1,intbranch2,intbranch3){

      inttotalIncome=branch1+branch2+branch3;

      System.out.print("Total company income: "+totalIncome);

    }

    //method for calculate the total tax

    publicvoidcountTotalTax(intbranch1,intbranch2,intbranch3){

      inttotalTax=branch1+branch2+branch3;

      System.out.print("Total company tax: "+totalTax);

    }

    //method for calculate the total weekely worked hours

    publicvoidcountTotalWeeklyHours(intbranch1,intbranch2,intbranch3){

      inttotalHours=branch1+branch2+branch3;

      System.out.print("Total weekly worked hours: "+totalHours);

    }

    //method to calculate the total expenditure

    publicvoidcountTotalExpenditure(intbranch1,intbranch2,intbranch3){

      inttotalExp=branch1+branch2+branch3;

      System.out.print("Total company expenditure: "+totalExp);

    }

     

 

}

    

Expert Solution
Step 1

By adding try and catch blocks to the code,it handles the exceptions.There is only one try block and more than one catch blocks.In try block ,we represent the code to be tested and in catch block it represents the type of exception.

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education