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); } }
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);
}
}
Step by step
Solved in 2 steps