Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

CC 103 – Intermediate Programming

Prefinal Project

TRY YOUR SKILLS


Instructions: Perform the following:

1. Create a class named 'Member' having the following members:


Data members
• Name
• Age
• Phone number
• Address
• Gross
• Hour work
• Rate per hour
It also has a method named printSalary () which computes the gross of the members
based on the number of hours worked and rate per hour. Two classes 'Employee' and
'Manager' inherits the 'Member' class. The 'Employee' and 'Manager' classes have data
members 'specialization' and 'department' respectively. Now, assign name, age, phone
number, address, hours work and rate per hour to an employee and a manager by making
an object of both of these classes and print the same.

class Member {

private String name;

private int age;

private String phoneNumber;

private String address;

private String gross;

private int hour_work;


CC 103 – Intermediate Programming
Prefinal Project

private double rate_per_hour;

public Member(String name, int age, String phoneNumber, String address, int
hour_work,double rate_per_hour) {

this.name = name;

this.age = age;

this.phoneNumber = phoneNumber;

this.address = address;

this.hour_work = hour_work;

this.rate_per_hour = rate_per_hour;

public void printSalary() {

System.out.println("Name: " + name);

System.out.println("Age: " + age);

System.out.println("Phone number: " + phoneNumber);

System.out.println("Address: " + address);

System.out.println("Hour work: "+ hour_work);

System.out.println("Rate per hour " + rate_per_hour+"\n");

}
CC 103 – Intermediate Programming
Prefinal Project

class Employee extends Member {

private String specialization;

public Employee(String name, int age, String phoneNumber,

String address, int hour_work, double rate_per_hour, String specialization) {super(name, age,
phoneNumber, address, hour_work, rate_per_hour); this.specialization = specialization;

class Manager extends Member{

private String department;

public Manager(String name, int age, String phoneNumber,

String address, int hour_work, double rate_per_hour, String department) {super(name, age,
phoneNumber, address, hour_work, rate_per_hour); this.department = department;

public class Main {

public static void main(String[] args) {


CC 103 – Intermediate Programming
Prefinal Project

Employee employee = new Employee("Andrew", 25, "+639385820544", "Home", 8, 150.5,"IT");

Manager manager = new Manager("John", 30, "+639276605593", "Earth", 8, 300.5,


"IT");employee.printSalary();

manager.printSalary();

2. Create a class named Square that contains data fields for height, width, and surfaceArea,
and a method named computeSurfaceArea (). Create a child class name Cube, which
contains an additional data field named depth, and a computeSurfaceArea () method that
overrides the parent method. Write an application that instantiates a Square object and a
Cube object and display the surface areas of the objects.

import java.util.Scanner;

class Square{

double height;

double width;

double surfaceArea;

public Square(double height, double width) {

this.height = height;

this.width = width;

}
CC 103 – Intermediate Programming
Prefinal Project

public void computeSurfaceArea(){

surfaceArea = height * width;

System.out.println("The Surface Area of a Square is " + surfaceArea); }

public static class Cube extends Square{

double depth;

public Cube(double height, double width, double depth){

super(height,width);

this.depth = depth;

public void computeSurfaceArea(){

double surfaceArea = (2 * height * width) + (2 * width * depth) + (2 * height *


depth);System.out.print("The Surface Area of a Cube is: " + surfaceArea);

public static void main(String args[]){

Scanner in = new Scanner(System.in);

double h,w,d;

System.out.print("Enter height: ");

h = in.nextDouble();

System.out.print("Enter width: ");

w = in.nextDouble();
CC 103 – Intermediate Programming
Prefinal Project

System.out.print("Enter depth: ");

d = in.nextDouble();

Square square = new Square(h,w);

System.out.println("\nSquare");

square.computeSurfaceArea();

Cube cube = new Cube(h,w,d);

System.out.println("\nCube");

cube.computeSurfaceArea();

You might also like