d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > I Need Help > Java Questions
123Next
Add Reply New Topic New Poll
Member
Posts: 1,406
Joined: Jul 19 2008
Gold: 1,493.00
Mar 18 2010 05:09pm
1.The classes that convert primitives to objects are called ____________ classes.
2.Suppose class Automobile has a static method called getMileage with the following signature:
public static double getMileage(String make, String model)
How would you call this method for a Ford Mustang and store the result in double mpg?
3.Name the three of the four primitive data types with which wrapper classes primarily deal.
4.Write a line of code that will convert double dx into an object. Call the object dd.
5.A) Write a line of code that will create an object that could be used to generate random numbers.
B: Use the object created in part "A" in a line of code that will generate integers in the range from 0 (inclusive) to 100 (inclusive).

This post was edited by DPAD171 on Mar 18 2010 05:10pm
Member
Posts: 1,406
Joined: Jul 19 2008
Gold: 1,493.00
Mar 18 2010 05:23pm
1. wrapper
3. int, double, and boolean
4. double dx = new double(dd);

are those right?

This post was edited by DPAD171 on Mar 18 2010 05:40pm
Member
Posts: 6,953
Joined: Sep 27 2003
Gold: 518.50
Mar 18 2010 06:11pm
Quote (DPAD171 @ Mar 18 2010 06:23pm)
1. wrapper
That is technically correct, in that it wraps the value as an object, but the more specific definition is "boxed value types."

2.
Code
getMileage("Ford", "Mustang");

Quote (DPAD171 @ Mar 18 2010 06:23pm)
3. int, double, and boolean
Yes. The others are short, long, float and char.
Quote (DPAD171 @ Mar 18 2010 06:23pm)
4. double dx = new double(dd);
Nope. The type double is a primative. Calling new doesn't work. You can rely on autoboxing:
Code
Double dd = dx;

5.
Code
new Random().nextInt(101)



Member
Posts: 1,406
Joined: Jul 19 2008
Gold: 1,493.00
Mar 18 2010 06:11pm
1. wrapper
2. double mpg = Automobile.getMileage(Ford, Mustang);
3. int, double, boolean
4. double dd = new double(dx);
5a. Random don = new Random();
5b. int num = don.nextInt(101);


How are these lookin? All right?
Member
Posts: 6,953
Joined: Sep 27 2003
Gold: 518.50
Mar 18 2010 06:14pm
Quote (DPAD171 @ Mar 18 2010 07:11pm)
2. double mpg = Automobile.getMileage(Ford, Mustang);

Error! You have to pass strings, not the values of tokens.

Member
Posts: 1,406
Joined: Jul 19 2008
Gold: 1,493.00
Mar 18 2010 06:16pm
Quote (ASBands @ Mar 18 2010 07:14pm)
Error!  You have to pass strings, not the values of tokens.


??
Member
Posts: 6,953
Joined: Sep 27 2003
Gold: 518.50
Mar 18 2010 06:24pm
Quote (DPAD171 @ Mar 18 2010 07:16pm)
??

Which word did you not understand?
Member
Posts: 1,406
Joined: Jul 19 2008
Gold: 1,493.00
Mar 18 2010 06:25pm
Quote (ASBands @ Mar 18 2010 07:24pm)
Which word did you not understand?


tokens. i dont get what u mean by that
Member
Posts: 11,637
Joined: Feb 2 2004
Gold: 434.84
Mar 18 2010 06:27pm
Quote (DPAD171 @ Mar 18 2010 08:25pm)
tokens. i dont get what u mean by that


He means pay attention in class, this shit is easy and you shouldn't really need to ask the internet about it.
Member
Posts: 6,953
Joined: Sep 27 2003
Gold: 518.50
Mar 18 2010 06:30pm
Quote (DPAD171 @ Mar 18 2010 07:25pm)
tokens. i dont get what u mean by that

http://dictionary.reference.com/browse/token
It means a symbol. In your statement, you're passing the symbols Ford and Mustang, both of which are completely meaningless. Pass string values, "Ford" and "Mustang"
Go Back To Programming & Development Topic List
123Next
Add Reply New Topic New Poll