Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Q6: (a) Read the java program carefully, compile the program and understand the compilation errors. Don't change access specifier for variables. What needs to be
Q6: (a) Read the java program carefully, compile the program and understand the compilation errors. Don't change access specifier for variables. What needs to be done to correct the compilation errors? Answer: class Box { private double width; private double height; private double depth; // compute and return volume double volume() { return width * height * depth; } Page 8 of 12 } public class BoxDemo { public static void main(String args[)) { Box myBox1 = new Box(); Box myBox2 = new Box(); myBox1.width = 10; myBox1.height = 20; myBox1.depth = 30; myBox2.width = 40; myBox2.height = 40; myBox2.depth = 40; double vol; // get volume of first box vol = myBox1.volume(); System.out.println("Volume for myBox1 is " + vol); // get volume of second box vol = my Box2.volume(); System.out.println("Volume is + vol); } } (b) Read the program carefully and implement try catch block to handle all the exceptions thrown in the try block. Answer: public class ExceptionHandlingClass{ public static void main(String[] args) { String dean = "Prof. Dr. Nazir Shah Khattak"; String chairman = "Sir Hamid Jan"; String coordinator 1 = "Sir Mudassir"; String coordinator2 = "Sir Niqash"; String str = "CSIT Dept SUIT"; int number; Page 9 of 12 int[] arrayYearsExp = {100, 200, 300, 400, 500); String deptProfile = str + "" + dean + + chairman + + coordinator 1+"" + coordinator2; System.out.println(deptProfile); number = Integer.parseInt(deptProfile); System.out.println(number); for(int i=0; i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started