The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 3 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
java
1.
A class called NumberList represents a sequence of real numbers (doubles). Write the specification (prototype and pre and post conditions, Not The Body) for a member method that adds the data from one NumberList to the end of this NumberList. Of course, no input or output should be involved.
Â
public class NumberList{
   private double[] a; private int na; //[0..na-1] holds the data
   // ... other stuff ...
      // your prototype and pre and post conditions:
2.
Person is a class that has just two fields, name and age. Assume it has public access methods getName and getAge and setName and setAge. Write a client method (i.e. a method that is not a member of Person) that is passed an array of Person and that returns an independent copy of the array. (Don't try to use clone.) Hint: the returned array must not refer to the same objects as the original array refers to. Don't forget to include the specification comments.
Â
3.
Complete this method:Â This method is NOT a member of the Employee class.
(The class Employee is the one we worked on in lab; each Employee has attributes name, age, and boss and has public methods getAge, getName, and getBoss. Its constructor throws BadEmployeeException when given bad data.)
Â
/**pre: list contains objects, some of which are Employees, but may
       contain other things also
 post: returns true iff at least one Employee in list has "Doug" as her boss
       throws an Exception if there are no Employees at all on the list
 */
static boolean hasDoug(ArrayList<Object> list) throws Exception{
Â
4.
Here is a class for you to complete. It represents a single clown, whose attributes are his name, his age, and the name of his circus. Add as little as possible, but provide and label (using a,b,c, and d) the following:
a) A constructor
b) An access method
c) Code that overloads a method or constructor
d) Code that overrides a method or constructor
Also, explain why your Clown class is or is not immutable:
Â
public class Clown extends Object{
   private String name,circus;
   private int age;
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly