Question

In: Computer Science

1. From the constructor, you infer that the name of the class containing the constructor must be_______ .


1. From the constructor, you infer that the name of the class containing the constructor must be_______ .

2. Fill in the blanks so that the statement will instantiate a JButton object and assigns it to variable of JButton type:

JButton btn= _______ ("OK");

3. Fill in the blanks to complete the description of the constructor in the corresponding UML class diagram:

+<>______( _____ : ______)

Solutions

Expert Solution

1. From the constructor, you infer that the name of the class containing the constructor must be_______ .

Ans: JButton

Explanation: Class name and Method name will be same in case of constructor's


________________________________________________________________________________________________________________

2. Fill in the blanks so that the statement will instantiate a JButton object and assigns it to variable of JButton type:
JButton btn= _______ ("OK");

Ans: JButton btn= new JButton("OK");

Explanation: Instantiate the class JButton by passing string "OK" that will create a button with label "OK"

________________________________________________________________________________________________________________

3. Fill in the blanks to complete the description of the constructor in the corresponding UML class diagram:
+<>______( _____ : ______)

Ans: +<>JButton( text : String )

Explanation: Method name is prefixed with <> word and parameters are enclosed in braces with parameter name first and then corresponding datatype.


Related Solutions

Create a class named BankAccount, containing: a constructor accepting a String corresponding to the name of...
Create a class named BankAccount, containing: a constructor accepting a String corresponding to the name of the account holder. a method, getBalance, that returns a double corresponding to the account balance. a method withdraw that accepts a double, and deducts the amount from the account balance. Write a class definition for a subclass, CheckingAccount, that contains: a boolean instance variable, overdraft. (Having overdraft for a checking account allows one to write checks larger than the current balance). a constructor that...
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must...
JavaScript - Create a class using "names" as the identifier. Create a constructor. The constructor must have elements as follow: first ( value passed will be String ) last ( value passed will be String ) age ( value passed will be Numeric ) The constructor will assign the values for the three elements and should use the "this" keyword Create a function, using "printObject" as the identifier printObject: This function will have three input parameters: allNames , sortType, message...
JAVA The class will have a constructor BMI(String name, double height, double weight). The class should...
JAVA The class will have a constructor BMI(String name, double height, double weight). The class should have a public instance method, getBMI() that returns a double reflecting the person's BMI (Body Mass Index = weight (kg) / height2 (m2) ). The class should have a public toString() method that returns a String like Fred is 1.9m tall and is 87.0Kg and has a BMI of 24.099722991689752Kg/m^2 (just print the doubles without special formatting). Implement this class (if you wish you...
To infer an outcome from a sample to the population, what assumption must be met for...
To infer an outcome from a sample to the population, what assumption must be met for all parametric statistics? A) Population is normally distributed B) Sample is small C) Population is small D) Population is large
Class Exercise: Constructor using JAVA Let’s define a Class together and have a constructor while at...
Class Exercise: Constructor using JAVA Let’s define a Class together and have a constructor while at it. - What should the Class object represent? (What is the “real life object” to represent)? - What properties should it have? (let’s hold off on the methods/actions for now – unless necessary for the constructor) - What should happen when a new instance of the Class is created? - Question: What are you allowed to do in the constructor? - Let’s test this...
The GroceryItem class must maintain the name of the item and its price (a double). You...
The GroceryItem class must maintain the name of the item and its price (a double). You must read the grocery data from file, and store each line's information in a single GroceryItem object. In other words, there should be one GroceryItem object created for each line in the file. Implement all standard and necessary getters and setters, as well as constructors. Also, implement a calculateWithTax method that takes a double parameter, and returns the price with the tax added. The...
In Angel, you will find a class called Employee. This class should include a constructor which...
In Angel, you will find a class called Employee. This class should include a constructor which sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will...
In Angel, you will find a class called Employee. This class should include a constructor which...
In Angel, you will find a class called Employee. This class should include a constructor which sets name to blanks and salary to $0.00 and a constructor which sets name to a starting name and salary to a set amount. Additionally, the class should include methods to set the name and salary and return the name and salary. Create another method to return the name and salary nicely formatted as a string (hint – research the toString method). You will...
Lab to be performed in Java. Lab: 1.) Write a class named TestScores. The class constructor...
Lab to be performed in Java. Lab: 1.) Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Write a driver class to test that demonstrates that an exception happens for these scenarios 2.) Write a class named InvalidTestScore...
Constructor: -empty body Class method 1: goodFriend - return string value, "I like you!" Class method...
Constructor: -empty body Class method 1: goodFriend - return string value, "I like you!" Class method 2: badFriend - return string value, "I don't like you!" Main Method: - create new Friend object - call goodFriend and badFriend using Friend object /* class header */ { /* constructor method header */ { } public static void main (String [] args) { Friend f = /* new Friend object */ // call goodFriend using Friend object // call badFriend using Friend...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT