Question
JAVA CODING The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem,
JAVA CODING
The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. Make sure the DebugPen class compiles without error, the DebugPen class methods work without error, the DebugFour2 class compiles without error and the DebugFour2 program accepts user input and displays the correct output.
An example of the program is shown below:
Enter a color ink for the pen >> Orange Enter a point size - fine, medium, or thick >> medium Default value pen: The pen has ink color black and a fine point. User value pen: The pen has ink color Orange and a medium point.
FIRST CODE:
public class DebugPen
{
private String color;
private String point;
public DebugPen()
{
color = "black";
point = "fine";
}
public DebugPen(String color, String point)
{
color = color;
point = point;
}
public String getColor()
{
return color;
}
public String getPoint()
{
return point;
}
}
SECOND CODE:
// This class uses a DebugPen class
// to instantiate two Pen objects
// One with default values
// and the other with user-supplied values
import java.util.Scanner;
public class DebugFour2
{
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
String color;
String point;
DebugPen pen1;
DebugPen pen2;
System.out.print("Enter a color ink for the pen >> ");
color = input.nextLine();
System.out.print("Enter a point size - fine, medium, or thick >> ");
point = input.nextLine();
pen1 = new DebugPen();
pen2 = new DebugPen(point, color);
System.out.println("Default value pen:");
display(pen1);
System.out.println("User value pen:");
display(pen22);
}
public static void display(FixDebugPen p)
{
System.out.println(" The pen has ink color " + p.getColor());
System.out.println(" and a " + p1.getPoint() + " point.");
}
}
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