OOP Assignment 02
OOP Assignment 02
1.
Create a Class MyMath. Within this class write three overloaded methods add(). The First Method
takes two integer parameter , add them and return the result. The second method takes an
integer number and return the sum of the series from 1 to the number. The third method takes
one integer and one floating value and work as type conversion (widing and narrowing).
2.
Write a program to create a room class, the attributes of this class is roomno, roomtype,
roomarea and ACmachine. In this class the member functions are setdata and displaydata.
[Output 03]
4.
The process of finding the largest value (i.e., the maximum of a group of values) is used frequently
in computer applications. For example, a program that determines the winner of a sales contest
would input the number of units sold by each sales person. The sales person who sells the most
units wins the contest. Write a Java application that inputs a series of 10 integers and determines
and prints the largest integer. Your program should use at least the following three variables: a.
counter: A counter to count to 10 (i.e., to keep track of how many numbers have been input and
to determine when all 10 numbers have been processed). b. number: The integer most recently
input by the user. c. largest: The largest number found so far.
}
}
[Output 05]
6.
Create a class called Employee that includes three pieces of information as instance variables—
a first name (typeString), a last name (typeString) and a monthly salary (double). Your class should
have 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, set it to 0.0. 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
[Output 06]
7.
Create a class called Date that includes three pieces of information as instance variables—a
month (typeint), a day (typeint) and a year (typeint). Your class should have a constructor that
initializes the three instance variables and assumes that the values provided are correct. Provide
a set and a get method for each instance variable. Provide a method displayDate that displays
the month, day and year separated by forward slashes(/). Write a test application named
DateTest that demonstrates classDate’s capabilities.
obj.DisplayDate();
}
}
[Output 07]
8.
Create class SavingsAccount. Usea static variable annualInterestRate to store the annual interest
rate for all account holders. Each object of the class contains a private instance variable
savingsBalance indicating the amount the saver currently has ondeposit. Provide method
calculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by
annualInterestRate divided by 12 this interest should be added to savingsBalance. Provide a static
method modifyInterestRate that sets the annualInterestRate to a new value. Write a program to
test class SavingsAccount. Instantiate two savingsAccount objects, saver1 and saver2, with
balances of $2000.00 and $3000.00, respectively. Set annualInterestRate to 4%, then calculate
the monthly interest and print the new balances for both savers. Then set the annualInterestRate
to 5%, calculate the next month’s interest and print the new balances for both savers.
SavingsAccount.modifyInterestRate (0.04);
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
SavingsAccount.modifyInterestRate(0.05);
saver1.calculateMonthlyInterest();
saver2.calculateMonthlyInterest();
}
public class InvoiceTest {