Homework/ Projects
3.14 (Employee Class) Create a class called Employee that includes three instance variables—a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test application named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10% raise and display each Employee’s yearly salary again.
Lab2/Hw2 due on 3/04/16 (includes exercise 5.4 and exercise 5.13)
Question 5.4 on page 191
Question 5.13 on page 193
5.13 (Factorials) Factorials are used frequently in probability problems. The factorial of a positive integer n (written n! and pronounced “n factorial”) is equal to the product of the positive integers from 1 to n. Write an application that calculates the factorials of 1 through 20. Use type long. Display the results in tabular format. What difficulty might prevent you from calculating the factorial of 100?
HW3/LAB3 due on 3/11/16
3.14 (Employee Class) Create a class called Employee that includes three instance variables—a first name (type String), a last name (type String) and a monthly salary (double). Provide a constructor that initializes the three instance variables. Provide a set and a get method for each instance variable. If the monthly salary is not positive, do not set its value. Write a test application named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s yearly salary. Then give each Employee a 10% raise and display each Employee’s yearly salary again.
Redo the exercise 3.14 a) such that you validate the Employee input (first name, lastname, salary)
b) Implement a Stack class data structure with methods : push(int i), pop(), top(), isempty(), displayinfo(),
You may implement the class stack as an array , or as a linked list.
You may have these class Stack instance variables ( private members) : int d_index , int d_size, int[] d_array.
push(int i) - pushes an integer i on top of the stack
int pop()- pops/removes an item from the top of the stack and returns its value/integer
int top() - returns the value of the item on top of the stack
boolean isempty()- is true if stack is empty, is false otherwise
void displayinfo() - displays messages if Stack is full, or Stack is empty, or the value on top of the Stack
Lab4/ HW4 due on April 22/2016
10.9 (Project: ShapeHierarchy) Implement the Shape hierarchy shown in Fig. 9.3. Each TwoDimensionalShape should contain method getArea to calculate the area of the two-dimensional shape. EachThreeDimensionalShape should have methods getArea and getVolume to calculate the surface area andvolume, respectively, of the three-dimensional shape. Create a program that uses an array of Shape references to objects of each concrete class in the hierarchy. The program should print a text descriptionof the object to which each array element refers. Also, in the loop that processes all the shapes in the array, determine whether each shape is aTwoDimensionalShape or a ThreeDimensionalShape. If it’s a TwoDimensionalShape, display its area. If it’s a ThreeDimensionalShape, display its area and volume..
10.13 (CarbonFootprint Interface: Polymorphism) Using interfaces, as you learned in this chapter,you can specify similar behaviors for possibly disparate classes. Governments and companies worldwide are becoming increasingly concerned with carbon footprints (annual releases of carbondioxide into the atmosphere) from buildings burning various types of fuels for heat, vehicles burning fuels for power, and the like. Many scientists blame these greenhouse gases for the phenomenon called global warming. Create three small classes unrelated by inheritance—classes Building, Car and Bicycle. Give each class some unique appropriate attributes and behaviors that it does not have in common with other classes. Write an interface CarbonFootprint with a getCarbonFootprint method.Have each of your classes implement that interface, so that its getCarbonFootprint method calculates an appropriate carbon footprint for that class (check out a few websites that explain how to calculate carbon footprints).Write an application that creates objects of each of the three classes,places references to those objects in ArrayList
Carbon footprint calculator at link https://www.nature.org/greenliving/carboncalculator/?src=sea.AWG.prnone.crv1&kt=mycarbonfootprintcalculator&gclid=CO_36efg78sCFcYehgod-aIKew