The Toy class is started below. Write three constructors for this class as explained in the comments below.
public class Toy
{
private String toyName;
private String toyMaker;
private double toyCost;
//default constructor
//constructor which has two String parameters
// constructor with three parameters
}
2. The Song class is provided below, but the constructors contain errors. Read the comments to determine the number of errors, then find the errors. Each line of code can have zero, one, or more than one errors. If a line of code contains errors, rewrite it correctly to the right.
public class Song
{
private String title;
private String artist;
private int trackMinutes;
private int trackSeconds;
// default constructor contains 2 errors
public void Song ______________________________
{
title = artist = ""; ______________________________
trackMinutes = trackSeconds = 0.0; ______________________________
}
// 1-arg constructor contains 5 errors
public song( title) ______________________________
{
title = title; ______________________________
artist = 0; ______________________________
trackMinutes = ""; ______________________________
trackSecond = 0; ______________________________
}
// 2-arg constructor contains 3 errors
public Song(String t, a) ______________________________
{
t = title; ______________________________
a = artist; ______________________________
trackMinutes = trackSeconds = 0; ______________________________
}
//4-arg constructor contains 4 errors
private Song(String t, String a, int min, int sec); ______________________________
{
title = t; ______________________________
artist = art; ______________________________
trackMin = min; ______________________________
trackSec = sec; ______________________________
}
}

Respuesta :

Answer:

Following are the solution to this question:

Explanation:

For question 1:

public class Toy//defining a class

{        private String toyName;//defining String variable

       private String toyMaker;//defining String variable

       private double toyCost;//defining double variable

       Toy() //defining default constructor Toy

       {

       }

       Toy(String aToyName, String aToyMaker)// defining parameterized constructor that accepts two String parameters

       {

       }

       Toy(String aToyName, String aToyMaker, double aToyCost)// defining parameterized constructor that accepts three parameters  

       {

       }

}

For question 2:

public class Song//defining a class Song

{

private String title;//defining String variable

private String artist;//defining String variable

private int trackMinutes;//defining integer variable

private int trackSeconds;//defining integer variable

Song() //defining default constructor

{

title = artist = "";//use String variable that holds null value

trackMinutes = trackSeconds = 0;//use integer variable that hold a value  

}

Song(String title)//use parameterized constructor that holds one parameter  

{

this.title = title;// use this keyword to hold title value

artist = "";// //hold value in String variable

trackMinutes = 0;//hold value in integer variable

trackSeconds = 0;//hold value in integer variable

}

Song(String t, String a) //use parameterized constructor that holds two String parameter

{

title=t; //hold value in String variable

artist=a;//hold value in String variable

trackMinutes = trackSeconds = 0;  //hold value in integer variable

}

Song(String t, String a, int min, int sec) //use parameterized constructor that takes 2 String and 2 integer parameters

{

title = t;//hold value in integer variable

artist = a;//hold value in String variable

trackMinutes = min;  //hold value in integer variable

trackSeconds = sec;   //hold value in integer variable

}

}

In the question 1, three constructor is declared, in which one is default and two is parameterized, that accepts two string parameter and two string and one double parameter.

In the question 2, four constructor is declared, in which one is default and three is parameterized, that accepts one, two, and four parameter.