Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts International Edition

Authors: David M. Kroenke

6th Edition International Edition

0133098222, 978-0133098228

More Books

Students also viewed these Databases questions

Question

What is its position?

Answered: 1 week ago

Question

What are the best practices for managing a large software project?

Answered: 1 week ago

Question

How does clustering in unsupervised learning help in data analysis?

Answered: 1 week ago