Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Debug the following program that has scope violations. Then, add comments that label the variable declerations as class, method, or blocm scope. 1 public class

Debug the following program that has scope violations. Then, add comments that label the variable declerations as class, method, or blocm scope. image text in transcribed
1 public class Testerclass 2 { 3 public static void main(String[] args) 4 5 6 Fraction f1 = new Fraction(); Fraction f2 - new Fraction(1,2); System.out.println(f1); System.out.println(f2.numerator / f2.denominator); 7 8 3 9 10 11 12 /* Class Fraction 13 class Fraction 14 15 W instance variables private int numerator; 17 private int denominator; 16 18 19 il constructor: set instance variables to default values public Fraction() 20 { 22 int d - 1; numerator - d; denominator - di 25 26 27 28 29 30 31 32 33 34 35 36 37 // constructor: set instance variables to init parameters public Fraction(int initNumerator, int initDenominator) { numerator - initNumerator; denominator - initDenominator; } public String toString() { // if the denominator is 1, then just return the numerator if (denominator -- d) { int newNumerator - 1; 3 return newNumerator + "/" + denominator; 38 39 (42)

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

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions

Question

5. Develop the succession planning review.

Answered: 1 week ago