Sunteți pe pagina 1din 27

LEEROY A BANANGA IH-65aH

JAVA ASSIGNMENTS
LAB 1-12

TASK 1

In this assignment, you will create a program that computes the distance an object will
fall in Earth’s gravity

Create a new class called GravityCalculator.

Copy and paste the following initial version:

class GravityCalculator {

public static void main ( String[] arguments ) {

double gravity =-9.81; // Earth's gravity in m/s^2

double initialVelocity = 0.0;

double fallingTime = 10.0;

double initialPosition = 0.0;

double finalPosition = 0.0;

System.out.println("The object's position after " + fallingTime +" seconds is " +


finalPosition + " m.");

3. Run it in.

What is the output of the unmodified program? Include this as a comment in the source
code of your submission.

Modify the example program to compute the position of an object after falling for 10
seconds, outputting the position in meters. The formula in Math notation is:

2
x(t) = 0.5 × at + vit + xi

Variable Meaning (ед. изм.) Value

a Acceleration (m/s2) -9.81

t Time (s) 10

vi Initial velocity (m/s) 0

xi Initial position (m) 0

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

Note: The correct value is -490.5 m. Java will output more digits after the decimal place,
but that is unimportant.

CODE:

package gravitycalculator;

public class GravityCalculator {

public static void main(String[] args) {

double a =-9.81;

double vi = 0.0;

double t = 10.0;

double xi = 0.0;

double xt = 0.5*(a*t*t) + vi*t + xi;

System.out.println("The objects position after "+ t +" seconds is "+


String.format("%.2f",xt) + "m.");

OUTPUT

TASK 2

Work with packages in Java. Create new project.

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

Call project Practice2.

Create two different packages: ua.edu.sumdu.actions and ua.edu.sumdu.tools.

In package ua.edu.sumdu.actions create class Operations. For this:

Type this code in class Operations:

In package ua.edu.sumdu.tools create class P and type this code.

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

OUTPUT

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

TASK 3

Work with primitive data types in Java. Create new project and add class Formula with
next methods:

method for setting value of variables function (variant in table);

method for calculate value of function;

method for print result of calculation.

Variants

2 При x=-4.5, y=0.75


,z=0.845  u=-55.6848

CODE

package parctice3;

public class Parctice3 {

public static void main(String[] args) {

double x=-4.5, y = 0.000075, z=84.5;

double u1 = Math.pow((8+Math.pow(Math.abs(x-y),2)+1),1./3.)/(x * x + y * y +
2);

double u2 = Math.exp(Math.abs(x-y)) * Math.pow((Math.pow(Math.tan(z),2)+1),x);

System.out.println("U= " + (u1-u2));

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

TASK 4

import java.util.Scanner;

import java.lang.*;

import java.io.IOException;

public class vec {

public static void main (String [] args)throws IOException {

vec first = new vec();

vec second = new vec();

vec result = new vec();

Scanner input = new Scanner(System.in);

first.set();

second.set();

System.out.println("ENTER ARITHMETIC OPERATION");

String operation = input.nextLine();

switch (operation){

case "+":

result = first.add(second);

break;

case "-":

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

result = first.subtract(second);

break;

case "*":

result = first.multiply(second);

break;

case "/":

result = first.divide(second);

break;

default:

System.out.println("NO SUCH ARITHMETIC OPERATION");

System.out.print("RESULT (VECTOR1"+operation+" VECTOR2) : ");

result.print();

System.out.print("Enter index you wish to replace: ");

int index = input.nextInt();

System.out.print("Input replacement number: ");

int value = input.nextInt();

result.setElement(index,value);

result.print();

System.out.print("Enter index you wish to get: ");

index = input.nextInt();

System.out.print("YOUR VALUE :"+ result.getElement(index));

System.out.println(" ");

TASK 5

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

Create projects Employees. In project Employees create class Employee which contain
next private attributes:

- identification number (id);

- static field int nextId, which keep next number of object;

- name (String name);

- surname (String surname);

- salary (double salary);

and corresponding methods:

Getters and setters – functions for private fields;

Constructors with parameters for initialization fields of class;

Method for increase salary on 10 % raiseSalary(double p);

void print() – method for print information about employee.

Create another class Manager which will be extends class Employee additional field

- double bonus

and method

setBonus().

Methods getSalary() and toString() must be changed, because in Manager they are
distinct.

CODE

package employee;

public class Employees {

public static void main(String[] args) {

Employee first = new Employee();

first.print();

System.out.println(" Manager Details ");

manager boss = new manager();

boss.print();

JAVA CLASS:

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

package employee;

import java.util.Scanner;

public class Employee {

private static int id = 1234;

private String fname;

private String surname;

private double salary;

Scanner input = new Scanner(System.in);

public static int getId() { return id; }

public String getName() { return fname + " " + surname; }

public double getSalary() { return salary; }

public void setSalary(double p ){ this.salary = p; }

public void setId(int id) { this.id = id; }

public void setFname(String fname) { this.fname = fname; }

public void setSurname (String surname) {this.surname = surname; }

public static int nextid() { return getId() + 1; }

public Employee() {

setId(nextid());

System.out.println( "ENTER YOUR FIRST_NAME:" );

setFname(input.nextLine());

System.out.println( "ENTER YOUR SURNAME:" );

setSurname(input.nextLine());

System.out.println( "ENTER THE AMOUNT OF SALARY: " );

setSalary( input.nextDouble());

public void print() {

System.out.println( " EMPLOYEE \nEMPLOYEE NO " + getId());

System.out.println( "FULL NAME :" + getName());

System.out.println( "SALARY : " + getSalary());

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

System.out.println();

class manager extends Employee {

private double bonus;

public void setBonus(double b) { this.bonus = b;}

public double getBonus() { return bonus; }

public manager(){

System.out.println( "ENTER THE BONUS AMOUNT: " );

setBonus(input.nextDouble());

@Override

public void print() {

System.out.println( " MANAGER \nMANAGER ID NO:" + getId());

System.out.println( "FULL NAME :" + getName());

System.out.println( "SALARY : " + getSalary());

System.out.println(); }

@Override

public double getSalary() {

raiseSalary();

double ttlsalary = super.getSalary() + getBonus();

return ttlsalary; }

public void raiseSalary() {

/*by 10% */

setSalary(super.getSalary() + (0.1 * super.getSalary()));

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

OUTPUT

TASK 6

Use code from previous practice #5. In class Employee add methods:

equals(); hashCode(); clone();

Check how this method work. Create two different objects and print them with using
methods toString () and them hash code. For checking method equals():

- compare two objects with similar data; compare two objects with different data.

For checking method clone () create object and his copy. Compare objects (they must be
equal). Print objects. In copy change salary. Compare objects. Print objects.

CODE:

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

import java.util.Scanner;
class employ implements Cloneable {
private static int id = 1234;
private String fname;
private String surname;
private double salary;
Scanner input = new Scanner(System.in);
public static int getId() { return id; }
public String getName() { return fname +" " + surname; }
public double getSalary() { return salary; }
public void setSalary(double p ){ this.salary = p; }
public void setId(int id) { this.id = id; }
public void setFname(String fname) { this.fname = fname; }
public void setSurname (String surname) {this.surname = surname; }
public static int nextid() { return getId() + 1; }
public employ() {
setId(nextid());
System.out.println("ENTER YOUR FIRST_NAME:");
setFname(input.nextLine());
System.out.println("ENTER YOUR SURNAME:");
setSurname(input.nextLine());
System.out.println("ENTER THE AMOUNT OF SALARY: ");
setSalary( input.nextDouble());
}
public void print() {
System.out.println("***EMPLOYEE***\nEMPLOYEE NO " + getId());
System.out.println("FULL NAME :" + getName());
System.out.println("SALARY : " + getSalary());
System.out.println();
}

@Override
public boolean equals(Object obj){
if (obj instanceof employ){
employ copy = (employ)obj;
return (fname.equals(copy.fname) && surname.equals(copy.surname) &&
id==copy.id && salary == copy.salary);}
else{ return false;}
}

@Override
public Object clone(){
try{
employ copycat = (employ)super.clone();
return copycat;}
catch(CloneNotSupportedException e){
throw new InternalError(e.toString()); }
}

@Override
public int hashCode(){
Double replicate = new Double(getSalary());

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

int result = 2*getName().hashCode() + 3*replicate.hashCode();


replicate = new Double(getId());
result += 4*replicate.hashCode();
return result ; }
}
class manager extends employ {
private double bonus;
public void setBonus(double b) { this.bonus = b;}
public double getBonus() { return bonus; }
public manager(){
System.out.println("ENTER THE BONUS AMOUNT: ");
setBonus(input.nextDouble());
}
@Override
public void print() {
System.out.println("***MANAGER***\nMANAGER ID NO:" + getId());
System.out.println("FULL NAME : " + getName());
System.out.println("SALARY : " + getSalary());
System.out.println(); }

@Override
public double getSalary() {
raiseSalary();
double ttlsalary = super.getSalary() + getBonus();
return ttlsalary; }
public void raiseSalary() {
/*INCREASE SALARY BY 10% */
setSalary(super.getSalary() + (0.1 * super.getSalary()));
}
}

public class employee {


public static void main(String[] args){
employ first = new employ();
first.print();
System.out.println("CREATING COPY...\n");
employ copy = (employ) first.clone();
copy.print();
if(first.equals(copy)){ System.out.println("OBJECTS ARE EQUAL");}
else{ System.out.println("OBJECTS NOT EQUAL");}
System.out.println("MAIN EMPLOY HASHCODE : "+ first.hashCode());
System.out.println("HASHCODE OF COPY : "+ copy.hashCode()+"\n");
copy.setSalary(700);
System.out.println("CHANGING SALARY OF COPY TO "+copy.getSalary()+"....\n");
copy.print();
if(first.equals(copy)){System.out.println("OBJECTS ARE EQUAL");}
else{ System.out.println("OBJECTS NOT EQUAL");}
System.out.println("HASHCODE OF COPY : "+ copy.hashCode());
System.out.println("------- :) -------"); } }

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

OUTPUT:

TASK 7

+Create class Student with attributes:

identification number (int id); String name; String surname; String group; array of
subjects (Subject [] subjects)which learned student.

+Create class Subject with attributes:

name of subject (String nameSubject); mark (Float mark).

+Create class Utils with static method for calculating average mark for every student

String getAverageMark(Students[] student).

In method main() create array of students (Student [] students) (count of students 5),


fill attributes every students (name, surname, group, array of subjects). Calculate
average mark for every student. For every student print all marks and average mark.

CODE:

import java.util.Scanner;
public class student {
Scanner input = new Scanner(System.in);
private static int id =1234;
private String firstname;
private String surname;
private static String group;
private static Subject[] subjects;
private String avg ;

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

public int getId() {return id;}


public void setId(int id) {student.id = id;}
public int increment (){return (getId()+1);}
public String getName() {return firstname+" "+surname; }
public void setName(String firstname,String surname){
this.firstname = firstname;
this.surname = surname; }
public String getGroup() {return group;}
public void setGroup(String group) { this.group = group; }
public Subject[] getSubjects() { return subjects;}
public void setSubjects(Subject[] subjects){this.subjects=subjects;}
public String getAvg() { return avg; }
public void setAvg() {
utils something = new utils();
this.avg = something.getAvgMark(); }
public void printer(){

System.out.println("STUDENT ID: "+getId()+"\nNAME: "+getName()+"\nGROUP:


"+getGroup()+"\nAVERAGE SCORE: "+getAvg());
}
public student(){
System.out.print("ENTER FIRST NAME: ");
String fname = input.next();
System.out.print("ENTER SURNAME: ");
String sname = input.next();
setName(fname,sname);
setId(increment());
}
public static class Subject{
private String name;
private float mark;
public void setName(String name) { this.name = name;}
public void setMark(float mark) {this.mark = mark; }
public Subject(){
Scanner input = new Scanner(System.in);
System.out.print("ENTER SUBJECT NAME: ");
String jina = input.next();
setName(jina);
System.out.print("ENTER "+jina+" SCORE: ");
float score = input.nextFloat();
setMark(score); }
}
public class utils {
public String getAvgMark(){
double a = 0 ;
Subject[] subj = getSubjects();
for (int i =0 ; i<subj.length;i++){ a += subj[i].mark; }
a = a/subj.length;
return String.valueOf(a); } }//END OF UTILS

}//END OF STUDENT
class seven {

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

public static void main(String[]args){


student[] pupils = new student [5];
student.Subject[] masomo = new student.Subject[2];
for (int i = 0; i < pupils.length; i++) {
pupils[i] = new student();
pupils[i].setGroup("IN65AH");
for (int j = 0; j < masomo.length; j++) { masomo[j] = new student.Subject(); }
pupils[i].setSubjects(masomo);
pupils[i].setAvg();
System.out.println(); }
System.out.println("^^^^^^STUDENT REPORT^^^^^^\n");
double avgall = 0;
for (int i =0; i<pupils.length;i++){
pupils[i].setId(pupils[i].increment());
pupils[i].printer();
System.out.println("------------------------");
avgall += Double.parseDouble(pupils[i].getAvg()); }
System.out.println("^^^^^^^^ CLASS AVERAGE: "+(avgall/pupils.length)+"
^^^^^^^^^");} }

OUTPUT:

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

TASK 8

Work with strings.

Variant 1

1. Given string of text (sentence). Print words with length 3 symbols.

CODE:

import java.util.Scanner;
public class eight {
public static void main(String[]args){
Scanner input = new Scanner(System.in);
System.out.println("ENTER SENTENCE");
String sentence = input.nextLine();

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

System.out.println("ENTER TASK NUMBER : ");


String op = input.next();
String[] arr = sentence.split(" ");
switch (op){
case "1" :
System.out.print("3 LETTER WORDS : ");
for (int i =0 ; i<arr.length;i++){
if(arr[i].length() == 3){ System.out.print(arr[i]+" "); }
else{ continue; } }
System.out.println();
break;
case "2" :
System.out.print("WORD WITH SAME FIRST & LAST LETTER : ");
for (int i =0 ; i<arr.length;i++){
if(arr[i].charAt(0) == arr[i].charAt(arr[i].length()-1)){
System.out.print(arr[i]+" ");
}
else{continue;} }
System.out.println();
break;
case "3" :
System.out.print("REMOVE WHATS BTWN \"(\" & \"( \" : ");
String pattern = "\\(.*?\\)";
String newsentence = sentence.replaceAll(pattern,"");
System.out.println(newsentence);
break;
default :
System.out.println("NO EXISTING TASK!.....");
break;
}
}
}

RESULTS:

TASK 9

Create hierarchy of classes of Vehicles. Super class is abstract class Vehicle With one
abstract method

public abstract class Vehicle {public abstract void move(int id); }

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

Giving three types vehicles: (Car); (Bicycle); (RollerSkates).

Every vehicle is individual class, which extends Vehicle and override method move(). For
example:

public class Bicycle extends Vehicle { public void move(int id) {

System.out.println(“Bicycle № ”+ id + “moving”); } }

In method main in loop random create array of different vehicle objects with special id,
besides abstract class Vehicle. Print elements of created array.

CODE:

import java.util.Random; 

abstract class Vehicle { public abstract void move(int id); } 

class bus extends Vehicle {

    @Override

    public void move(int id){ System.out.println("BUS No : "+id +" moving!"); }

class bicycle extends Vehicle{

    @Override

     public void move(int id){ System.out.println("BICYCLE No : "+id +" moving!"); }

class rollerskates extends Vehicle{

    @Override

     public void move(int id){System.out.println("ROLLERSKATES No : "+id +" moving!");


}

public class Nine {

 public static void main(String[] args){

    Random random = new Random();

    for (int i = 0; i<3; i++){

        int value = 1 + (int) (Math.random()*3);

        switch(value){

            case 1: 

                bus bus01 = new bus(); 

                int bid = random.nextInt(1000); 

                bus01.move(bid);

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

                break; 

            case 2: 

                bicycle bicycle1 = new bicycle(); 

                int cid = random.nextInt(1000); 

                bicycle1.move(cid);

                break; 

            case 3: 

                rollerskates roller1 = new rollerskates(); 

                int rid = random.nextInt(1000); 

                roller1.move(rid);

                break; 

            default:

                System.out.print("ERROR");

                break; } } } }

OUTPUT:

TASK 10

Create interface Run with next methods:

– Method for print name of object;

– Method for getting max speed of transport;

– Method for getting weight of transport;

– Method move() for moving transport.

Create abstract class Machine, which implement interface Run with next attributes
(name, weight, max speed, count of passenger). Create class Car and Bus which extends
Machine. Define constructors with corresponding parameters for creating objects and
override methods. Try to create objects of classes Car and Bus and invoke them
methods.

CODE:

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

import java.util.Random;
interface Run{
void print();
int getmaxspeed();
int getweight();
void move();
}
abstract class machine implements Run{
String name;
int weight, maxSpeed, countOfPassengers;
}
class car extends machine{
@Override
public void print(){ System.out.println("CAR NAME: "+name+"\nMAX SPEED:
"+getmaxspeed()+"\nWEIGHT: "+getweight()+"\nNo OF PASSENGERS:
"+countOfPassengers); }
public int getmaxspeed(){return maxSpeed; }
public int getweight(){return weight; }
public void move(){ System.out.println("car now moving!..");}

public car(String name, int maxspeed, int weight, int count){


this.name = name;
this.weight = weight;
this.maxSpeed = maxspeed;
this.countOfPassengers = count;
}
}
class bus extends machine{
@Override
public void print(){ System.out.println("BUS NAME: "+name+"\nMAX SPEED:
"+getmaxspeed()+"\nWEIGHT: "+getweight()+"\nNo OF PASSENGERS:
"+countOfPassengers); }
public int getmaxspeed(){ return maxSpeed; }
public int getweight(){return weight; }
public void move(){ System.out.println("bus now moving!..");}
public bus(String name, int maxspeed, int weight, int count){
this.name = name;
this.weight = weight;
this.maxSpeed = maxspeed;
this.countOfPassengers = count;
}
}
public class ten {
public static void main(String[] args){
Random rand = new Random();
String[] brand = new String[]{"TOYOTA","LADA","SUZUKI"};
for(int i=0 ; i<3; i++){
int value = (int)(Math.random()*2)+1;
switch (value){
case 1:
int max= rand.nextInt(200)+100;
int weight = rand.nextInt(300)+100;

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

int count = rand.nextInt(5)+1;


String name = brand[rand.nextInt(3)];
car gari = new car(name,max,weight,count);
gari.print();
gari.move();
break;
case 2:
int bmax= rand.nextInt(200)+100;
int bweight = rand.nextInt(300)+100;
int bcount = rand.nextInt(20)+1;
String bname = brand[rand.nextInt(3)];
bus buss = new bus(bname,bmax,bweight,bcount);
buss.print();
buss.move();
break;
default:
System.out.println("ERROR");
break;
} System.out.println("\n------------------\n"); } } }

OUTPUT:

TASK 11

Create class Person which contain name, surname and patronymic. Implement interface
Comparable by class Person for sequencing objects by surname. Check work of interface
Comparable with using collection TreeMap.

CODE:

import java.util.*;
class person implements Comparable<person>{

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

private String firstname;


private String surname;
private String patronymic;
public String getSurname() { return surname; }
public void setSurname(String surname) { this.surname = surname; }
}

public person(String firstname, String surname, String patronymic) {


this.firstname = firstname;
this.surname = surname;
this.patronymic = patronymic;
}

@Override
public String toString() {
return "person{" +
"firstname='" + firstname + '\'' +
", surname='" + surname + '\'' +
", patronymic='" + patronymic + '\'' +
'}';
}
@Override
public int compareTo(person p){
return this.getSurname().compareTo(p.getSurname());
}
}
public class eleven {
public static void main(String[] args) {
TreeMap<Integer,person> mtu = new TreeMap<>();
mtu.put(101,new person("sarah","c","sanya"));
mtu.put(102,new person("yusuf","b","suleiman"));
mtu.put(103,new person("intisar","a","alfonzo"));

TreeMap sorted = sortbysurname(mtu);


Set set = sorted.entrySet();
Iterator it = set.iterator();

while(it.hasNext()){
Map.Entry p = (Map.Entry)it.next();
System.out.println( p.getKey()+" - "+p.getValue()); }
}
public static <K,V extends Comparable<V>> TreeMap<K,V> sortbysurname(final
TreeMap<K,V> map){
Comparator<K> com = new Comparator<K>() {
@Override
public int compare(K o1, K o2) {

return map.get(o1).compareTo(map.get(o2)); }
};
TreeMap<K,V> sortedd = new TreeMap<K,V>(com);
sortedd.putAll(map);
return sortedd; } }

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

OUTPUT:

TASK 12

Using classes from practice #5 create your own classes exception with constructors.
Create class exception FieldLengthLimitException. For example, you can specify the
maximum number of characters for the employee’s first and last name. If you try to
assign a string with a large number of characters to the name field,throw the
FieldLengthLimitException (passing the corresponding text message) to it, which you
catch in the main () method and inform the user about the problem.

Also create an IncorrectSalaryException class. Throw this type of exception when trying
to assign a negative salary. And also catch it in the main () method.

All exceptions defined in the program must be inheritors of the Exception class.

CODE:
import java.util.Scanner;
class worker {
private static int id = 1234;
private String fname;
private String surname;
private double salary;
Scanner input = new Scanner(System.in);
public static int getId() { return id; }
public String getName() { return fname +" " + surname; }
public double getSalary() { return salary; }
public void setSalary(double p ){ this.salary = p; }
public void setId(int id) { this.id = id; }
public void setFname(String fname) { this.fname = fname; }
public void setSurname (String surname) {this.surname = surname; }
public static int nextid() { return getId() + 1; }
public worker() {
boolean flag = true;
setId(nextid());
while (flag) {
try {
System.out.println("ENTER YOUR FIRST_NAME:");

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

String s = input.nextLine();
if (s.length() > 10) {
throw new FieldLengthLimitException("LENGTH LIMIT 10 : PLEASE
RETRY \n");
} else {setFname(s); flag = false; }
} catch (FieldLengthLimitException e) {System.out.println(e); }
}
flag = true;
while(flag) {
try {
System.out.println("ENTER YOUR SURNAME:");
String s = input.nextLine();
while (flag) {
if (s.length() > 10) {
throw new FieldLengthLimitException("LENGTH LIMIT 10 : PLEASE
RETRY \n");
} else {setSurname(s); flag = false; }
}
} catch (FieldLengthLimitException e) {System.out.println(e); }
}
flag = true;
while(flag) {
try {
System.out.println("ENTER THE AMOUNT OF SALARY: ");
double s = input.nextDouble();
while (flag) {
if (s < 0) {
throw new IncorrectSalary("LESS THAN 0 SALARY ERROR : PLEASE
RETRY \n");
} else {setSalary(s); flag = false; }
}
} catch (IncorrectSalary e) {System.out.println(e); }
}
}
public void print() {
System.out.println("***EMPLOYEE***\nEMPLOYEE NO " + getId());
System.out.println("FULL NAME :" + getName());
System.out.println("SALARY : " + getSalary());
System.out.println();
}

}
class managerr extends worker {
private double bonus;
public void setBonus(double b) { this.bonus = b;}
public double getBonus() { return bonus; }
public managerr(){
System.out.println("ENTER THE BONUS AMOUNT: ");
setBonus(input.nextDouble());
}
@Override

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

public void print() {


System.out.println("***MANAGER***\nMANAGER ID NO:" + getId());
System.out.println("FULL NAME : " + getName());
System.out.println("SALARY : " + getSalary());
System.out.println(); }

@Override
public double getSalary() {
raiseSalary();
double ttlsalary = super.getSalary() + getBonus();
return ttlsalary; }
public void raiseSalary() {
/*INCREASE SALARY BY 10% */
setSalary(super.getSalary() + (0.1 * super.getSalary()));
}
}

class FieldLengthLimitException extends Exception{


public FieldLengthLimitException (String s){ super(s); }
}
class IncorrectSalary extends Exception {
public IncorrectSalary (String s){ super(s); }
}

public class twelve {


public static void main(String[] args){
worker first = new worker();
first.print(); } }

Руденко Максим Сергійович


LEEROY A BANANGA IH-65aH

Руденко Максим Сергійович

S-ar putea să vă placă și