I am new to Java and new to the board. I am working on a made up program that uses inheritance to create seperate classes(in seperate files) and includes intentional errors and error handling to correct the errors. The problem is, the variables that I created are not seeming to transfer to the "Class ExceptionC." I receive errors- "Cannot find variable C." "Cannot find variable "ExceptionB"
Suggestions greatly appreciated!
Thanks a million,
-Sof
public class ExceptionA //extends Exception
{
public String A;
public int B;
public int C;
public ExceptionA( String a, int b, int c )
{
A = a;
B = b;
C = c;
}
public void setA ( String a )
{
A = a;
}
public String getA ( String a )
{
return a;
}
public void setB ( int b )
{
B = b;
}
public int getB ( int b )
{
return b;
}
public void setC ( int c )
{
C = c;
}
public int getC ( int c )
{
return c;
}
public String toString()
{
return String.fromat( "This is the entered data a: %s b: %s c:%s ", getA(), getB(), getC() );
}
public abstract int except();
}
}
public class ExceptionB extends ExceptionA
{
private int calculatedResult;
private int result;
public ExceptionB( String a, int b, int c )
{
super( a, b, c );
setCalculatedResult( result );
}
public int setCalculatedResult( int result )
{
calculatedResult = result < 0 ? 0 : result;
}
public int getCalculatedResult()
{
return calculatedResult;
}
public int exceptions()
{
return getCalculatedResult();
}
public String toString()
{
return String.format( "This is the calculated Data: %s", super.toString(), getCalculatedResult() );
}
public int except();
{
}
}
public class ExceptionC
{
public static void main(String args[])
{
ExceptionB exceptionB = new ExceptionB( "Hello", 150, 0 );
System.out.println( "This is the Data" );
while ( C == 0 )
{
System.out.println( ExceptionB );
try
{
System.out.print( "We are going to try to divide %s by %s ", getA(), getB() );
int result = quotient( A, B );
}
catch ( Exception exception )
{
System.out.println( "This division results in error. Characters cannot be used in Arithmetic calculations." );
}
try
{
System.out.println( "We are going to try to divide %s by %s .", getB(), getC() );
int result = quotient( B, C );
}
catch ( ArithmeticException arithmeticexception )
{
System.out.println( "This division results in error. Integers cannot be divided by zero." );
}
finally
{
System.out.println( "We are going to try to divide %s by %s .", getC(), getB() );
int result = quotient( C, B );
System.out.println( "This division results is successful. Zero can be divided by another integer. The result is %s", getresult() );
}
for ( int j = 0; j < exception.length; j++ )
System.out.printf( "Exception %s is %s\n", j, exceptions[ j ].getClass .getName() );
}
}
}

New Topic/Question
Reply



MultiQuote




|