$25.00 Java (Classes: Constructors/Accessing Class Members )
- From Computer-Science: Object-Oriented-Programming , Computer-Science: Programming-Methods
- Closed, but you can still post tutorials
- Due on Nov. 01, 2009
- Asked on Oct 30, 2009 at 8:05:10PM
Q:1.Suppose you are given the following
mainmethod:public class BookWork {
public static void main() {
BoxOfBooks b = new BoxOfBooks(43,70.3);
System.out.println("There are " + b.getCount() + " books.");
System.out.println("They weigh " + b.getWeight() + " pounds.");
}
}
This is one example of how to use theBoxOfBooksclass. Running themainmethod as written above gives the following output.There are 43 books.
They weigh 70.3 pounds.
Here is an incomplete version of theBoxOfBooksclass. Complete the definition so that theBookWorkdriver will work properly with your enhanced definition forBoxOfBooks.
// <![CDATA[ setLineNumbers(false); setStartLineNumber(1); setJavaCodeFontSize(3); document.write(formatJavaCode("public class BoxOfBooks {\n\n private int count;\n private double weight;\n\n public BoxOfBooks(int c, double w) {\n count = c;\n weight = w;\n }\n\n public int getCount() {\n return count;\n }\n")); ]]> public class BoxOfBooks {
private int count;
private double weight;
public BoxOfBooks(int c, double w) {
count = c;
weight = w;
}
public int getCount() {
return count;
}
} // end class BoxOfBooks
2.Suppose you are given the followingmainmethod:public class OrangeTester {
public static void main(String[] args) {
System.out.println("I'm buying some oranges.");
Orange fruit = new Orange(3);
System.out.println("There are " + fruit.getNumber() + " oranges.");
System.out.println("Now I have more.");
fruit.setNumber(7);
System.out.println("Now there are " + fruit.getNumber() + " oranges.");
}
}
This is one example of how to use theOrangeclass. Running themainmethod as written above gives the following output.I'm buying some oranges.
There are 3 oranges.
Now I have more.
Now there are 7 oranges.
Here is an incomplete version of theOrangeclass. A method definition is missing. Complete the class definition so that theOrangeTesterdriver will work properly with your enhanced definition forOrange.
// <![CDATA[ setLineNumbers(false); setStartLineNumber(1); setJavaCodeFontSize(3); document.write(formatJavaCode("public class Orange {\n\n private int number;\n\n public Orange(int n) {\n number = n;\n }\n\n public void setNumber(int n) {\n number = n;\n }\n")); ]]> public class Orange {
private int number;
public Orange(int n) {
number = n;
}
public void setNumber(int n) {
number = n;
}
// <![CDATA[ setLineNumbers(false); setStartLineNumber(1); setJavaCodeFontSize(3); document.write(formatJavaCode("} // end class Orange")); ]]> } // end class Orange
#########
#########
The full list of questions (22 questions) is attached under the file's name OWL.java
########
########
Attachments:My Documents.zip (3K)
OWL.java (19K)



