I need some help here. I have two assignments here, that I am supposed to finish all by myself, but I just can�t get my head around this�and when I ask the �teacher�, he just says that he won�t help me. I�m on my own. I don�t know what kind of school this so called teacher went to, but I think that I should be allowed to ask for help, so now I�m asking you guys instead. I�m sure you can tell me what to do here. I thank you for all possible assistance that I can get here, because I myself am merely a beginner and I don�t know much about anything when it comes to this sort of thing, so�any help would be much appreciated�thanks in advance.
/Yurij
5a
Write a class which will be called Triangle. The class will be used as a model for different objects (triangles).
Test the class Triangle in a program (main class).
a)- Create two objects of Triangle. The objects� base and height can get different values. Print the objects� attributes (base and height) and their area (print method).
b)- Change base and height for existing objects (set methods) and print the altered objects� attribute once more.
c)- Get base and height for an object (get methods) and print them.
The test run should look like this:
a:
Object 1:
The area of a triangle with the base 3 and the height 8 is: 12.0
a:
Object 2:
The area of a triangle with the base 4 and the height 9 is: 18.0
b:
Object 1 with altered base:
The area of a triangle with the base 5 and the height 8 is: 20.0
b:
Object 2 with altered height:
The area of a triangle with the base 4 and the height 5 is: 10.0
c:
The objects� attributes printed using �get methods�:
The area of object 1 with the base 5 and the height 8 is: 20.0
Press Enter to exit_
class Triangle{
: // instance variables
public Triangle(int base, int height){
//Write code here
}
:
: //set and get methods.
:
public void print(){
//Write code here
}
}
5b
A company needs a program for their salary system to their employees. The model is to be based on so called �hourly wage�. The program should be able to calculate the employee�s salary (based on hourly wage and amount of hours) and print name, amount of hours and calculated salary. The employees who work more than 40 hours get overtime for the hours that exceed 40 and are calculated like this:
(40*hourly wage)+(amount of hours � 40)*(1 � )*hourly wage
To avoid too much overtime, a warning message should be printed when overtime exceeds 30 hours during a two week period.
Here is a possible scenario that is expected of the salary system (the program):
A user puts in the employee�s name and hourly wage. Then the amount of working hours is put in and the salary is calculated and printed week by week. You finish by pressing 0 and then the total amount of overtime hours shall be printed.
Test run: Your program should contain a class �Employee� which has for instance variables, one constructor and at least three methods: (salaryCalculation (int hours), getName() and toString().
As seen above, the program reads name and hourly wage. Then the program should create an object of the class �Employee� for the person put in.
class Employee {
// Instance variables
private
String name;
private int hourly_wage;
private int lastWeeksOvertime;
private int totalOvertime;
// Methods
A constructor
A method for calculating salary
A method that returns name
A method called �toString()� and which shall return the last
text in the test run. (Name: Peter Johnson hourly wag�)
}
class Program5b {
public static void main(String[] args) {
// declaration of variables
// declaration of an object e.g. Employee;
�
:
:
�
}
}