Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Advanced Java Programming with Object-Oriented Programming Design VERY IMPORTANT

ID: 3711841 • Letter: A

Question

Advanced Java Programming with Object-Oriented Programming Design

VERY IMPORTANT NOTE, PLEASE READ BEFORE ANSWERING THE QUESTION BELOW!!: Because I'm in an advanced Java class that must use Object-Oriented Programming Design in all assignments, the answer for the question below MUST contain private variables, least 2 CLASSES, accessors and mutators for the private variables. You can use any other additional other object-oriented design (OOD) concepts if you want to but private variables, least 2 CLASSES, accessors and mutators for the private variables are a must! I've seen answers to the question below already posted, however they don't utilize object-oriented design (OOD) concepts such as a private variables, least 2 CLASSES, accessors and mutators for the private variables etc, which is required for this advanced Java programming class. So please answer the question meet the requirements for this question. Basically, I need advanced Java object-oriented design concepts for simple programs so here's to hoping this works out and if it does, I'll give a thumbs up, I promise!!!

Question:(Constructor Failure) Write a program that shows a constructor passing information about constructor failure to an exception handler. Define class SomeClass, which throws an Exception in the constructor. Your program should try to create an object of type SomeClass and catch the exception that’s thrown from the constructor.

Explanation / Answer

SomeClass.java

public class SomeClass{

private int a;

private String b;

public int getA() {

return a;

}

public void setA(int a) {

this.a = a;

}

public String getB() {

return b;

}

public void setB(String b) {

this.b = b;

}

public SomeClass(int a, String b) throws Exception{

if(a == 0 || b.equals(""))

throw new Exception("Null Exception");

this.a = a;

this.b = b;

}

@Override

public String toString() {

return "SomeClass [a=" + a + ", b=" + b + "]";

}

}

Driver.java

public class Driver {

public static void main(String[] args){

SomeClass sc;

try {

sc = new SomeClass(0, "Hello world");

System.out.println(sc);

} catch (Exception e) {

e.printStackTrace();

}

}

}

**Comment for any further queries.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote