0% found this document useful (0 votes)
4 views4 pages

Java 2

The document contains Java code for a program that includes classes for checking isograms, managing job information, and handling person data. It allows users to input person details, calculates total and average salaries, and identifies the person with the maximum salary. Additionally, it provides functionality to give bonuses to engineers and displays the details of all persons.

Uploaded by

92330363
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Java 2

The document contains Java code for a program that includes classes for checking isograms, managing job information, and handling person data. It allows users to input person details, calculates total and average salaries, and identifies the person with the maximum salary. Additionally, it provides functionality to give bonuses to engineers and displays the details of all persons.

Uploaded by

92330363
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Saad ldin Hussein

1)

public class IsogramChecker {


public static boolean isIsogram(String word) {
word = word.toLowerCase();
boolean[] charMap = new boolean[26];

for (char ch : word.toCharArray()) {


if (charMap[ch - 'a']) {
return false;
}
charMap[ch - 'a'] = true;
}
return true;
}

public static void main(String[] args) {


System.out.println(isIsogram("computer"));
System.out.println(isIsogram("banana"));
System.out.println(isIsogram("uncopyrightable"));
}
}

2)
public class Job {
private String category;
private double salary;

public Job(String category, double salary) {


this.category = category;
this.salary = salary;
}

public String getCategory() {


return category;
}

public void setCategory(String category) {


this.category = category;
}

public double getSalary() {


return salary;
}

public void setSalary(double salary) {


this.salary = salary;
}

public String toString() {


return category + ", " + salary + "$";
}
}

3)
public class Person {
private String name;
private Job job;
private static int employeesCount = 0;
private static double totalSalary = 0;
private double actualSalary;

public Person(String name, Job job) {


this.name = name;
setJob(job);
}

public String getName() {


return name;
}

public void setJob(Job job) {


if (this.job != null) {
totalSalary -= this.actualSalary; // Remove old salary from total
}
this.job = job;
this.actualSalary = job.getSalary();
totalSalary += actualSalary;
employeesCount++;
}

public Job getJob() {


return job;
}

public void bonus(double value) {


this.actualSalary += value;
totalSalary += value;
}

public static int getEmployeesCount() {


return employeesCount;
}

public static double getTotalSalary() {


return totalSalary;
}

public String toString() {


return "Name: " + name + ", " + "Job: " + job.getCategory() +
", Actual Salary: " + actualSalary + "$, Total Salaries: " + totalSalary + "$";
}
}

4)
import java.util.Scanner;

public class Main {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Person[] persons = new Person[

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


System.out.print("Enter Person information (name job salary): ");
String name = scanner.next();
String jobCategory = scanner.next();
double salary = scanner.nextDouble();
Job job = new Job(jobCategory, salary);
persons[i] = new Person(name, job);
}

persons[0].setJob(new Job("Eng", 1500));

persons[0].getJob().setCategory("Engineer");

System.out.println("\nThe actual salary of every person:");


for (Person p : persons) {
System.out.println(p.getName() + ": " + p.getJob().getSalary() + " $");
}

double averageSalary = Person.getTotalSalary() / Person.getEmployeesCount();


System.out.println("\nThe average of all salaries: " + averageSalary + " $");

Person maxSalaryPerson = persons[0];


for (Person p : persons) {
if (p.getJob().getSalary() > maxSalaryPerson.getJob().getSalary()) {
maxSalaryPerson = p;
}
}
System.out.println("The Person with the maximum actual salary: " +
maxSalaryPerson.getName());

for (Person p : persons) {


if (p.getJob().getCategory().equals("Engineer")) {
p.bonus(100);
}
}

System.out.println("\nThe description of all the persons:");


for (Person p : persons) {
System.out.println(p);
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy