NhoMt
<font color=#ff00ff>Dễ Thương</font>
- 16/4/03
- 5,669
- 11
Thứ 4 trả bài .....
Giúp iêm với ....
Góp ý nhanh nha
Giúp iêm với ....
Góp ý nhanh nha
Which ONE of the following is TRUE?
a. A subclass may delete instance variables that are declared in its superclass.
b. A subclass may declare new instance variables that are not declared in its superclass
c. A subclass may delete messages that are defined in its superclass
d. A subclass must use all of the methods defined in its superclass.
/////////////////////////////////
Consider a private static variable called votingAge declared in a class called Person. Assume that the following expressions are in an instance method in the Person class. Which ONE of the expressions would generate a compiler error?
a. System.out.println(Person.votingAge);
b. System.out.println(this.votingAge);
c. System.out.println(votingAge);
d. Person.votingAge = 21;
/////////////////////////////////
What is the ActionEvent class?
What is a static method ?
In writing the code for a method, a programmer might use the keyword this. When the method is invoked from somewhere in the program, what does this refer to?
What is the effect of writing final when declaring a variable reference?
/////////////////////////////////////////////////////////////////
Consider a class called Part. Every Part has a name, and a price. The name and price are set when the Part is created. Consider another class called an Assembly. An assembly has a name, exactly 3 parts, a date, a total price and a discount percentage. The name, the discount percentage and all three parts must be specified when the assembly is created. The date of the assembly is the date it was created. The total price of the assembly is the sum of the prices of the parts. The discounted price of the assembly is the total price less the discount. When a part is asked to display itself it looks like the following:
Engine $6000
When an assembly is asked to display itself it looks like:
Automobile
assembled on 12/1/2006
consists of
Engine $6000
Frame $7000
Interior $4000
Total $17000
Discount 10%
Discounted Price $15300
Here is the code for the classes Part and Assembly, along with a program class called Test that creates an assembly and displays it. Fill in the ???? with the missing code.
////////////////////////////////////////
public class Assembly {
/* Instance Variables */
private String name;
private Date today;
private int discount;
//define instance variables named parta, partb, partc
private ????;
private ????;
private ????;
/*
Each of the instances represents an Assembly that has a name, date, a discount percentage and three parts.
*/
public Assembly(String assemblyName,
int m, int d, int y,
int percentage,
????, ????, ???? ) {
/*Initialize object to have the given name, discount rate, date and the given three
parts (3 points)*/
????
????
????
????
????
????
}
public int price() {
/*Return my total un-discounted price in dollars.*/
return ??? + ???? + ????;
}
public int discountedPrice() {
/*Return my discounted price in dollars.*/
double price;
price = ?????? ;
return (int)(price);
}
public void display() {
System.out.println(???);//display name
System.out.print("\t assembled on");
System.out.println(????);//display date
System.out.println("\t consists of");
System.out.print("\t");
this.part1.display();
System.out.print("\t");
this.part2.display();
System.out.print("\t");
this.part3.display();
System.out.print("\tTotal $");
System.out.println(???);//display price
System.out.print("Discount ");
System.out.print(????);//display discount
System.out.println("%");
System.out.print("Discounted price $");
System.out.println(????);//display discounted price
}
}
////////////////////////////////////////////
public class Part {
/* Instance Variables */
private String name;
private int price;
public Part(String partName, int value) {
/*Initialize object to have the given name and price in dollars.*/
????
????
}
public void display() { //
/*Display part name*/
System.out.print(????);
System.out.print(" $");
/*Display part price*/
System.out.println(????);
}
public int price() {
/*Return price in dollars. */
???????
}
}
/////////////////////////////////////////////////
public class Test {
/*
Test the Assembly and Parts classes by creating an assembly and displaying it.
*/
public static void main(String args[]) {
/*
Create the 3 part objects part1, part2, part3, create the an assembly object that contains them and
display the assembly. */
//Create object part1 with the values "Engine", 6000
??????
//(Create object part2 with the values"Frame", 7000;
?????
//Create object part3 with the values"Interior", 4000;
?????
//Create object assembly with the values"Automobile", 12,1,2006, 10, part1, part2, part3;
??????????
assembly.display();
}
}
/////////////////////////////////////////////////
//Date.java
// Declaration of the Date class.
public class Date {
private int month; // 1-12
private int day; // 1-31 based on month
private int year; // any year
// Constructor:
public Date( int mn, int dy, int yr )
{ month = mn;
day = dy;
year = yr;
}
// Create a String of the form month/day/year
public String toString()
{ return month + "/" + day + "/" + year; }
}