Method machining in Report class prints information about employee and sends email. Please refactor this code by extracting each task into separate method. Propose the other solutions for improving quality of the code.
class Report {
public double getTaxes (String name, String address, String idNumber) {
}
public void machining (String name, String address, String idNumber, Session session, String email) {
double taxes;
String content;
MimeMessage message;
taxes =getTaxes(name, address, idNumber);
System.out.println("\nName \t" + name);
System.out.println("\nHome Address \t" + address);
System.out.println("\nSocial security number \t" + idNumber);
System.out.println("\nTaxes \t" + taxes);
content = "\nName \t" + name;
content = "\nHome Address \t" + address;
content = "\nSocial security number \t" + idNumber;
content = "\nTaxes \t" + taxes;
try {
message = new MimeMessage(session);
message.setFrom (new InternetaAddress("taxes@government.org"));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(email));
message.setSubject("Taxes for " + name);
message.setText(content);
Transport.send(message);
}
catch (Exception ex) {
}
}
}
Андрей Мельник
28 уровень
Извините за оффтоп, помогите сделать задачу или подскажите куда двигаться :
Обсуждается
Комментарии (1)
- популярные
- новые
- старые
Для того, чтобы оставить комментарий Вы должны авторизоваться
Евгений Enterprise Java Developer Expert
22 мая 2019, 11:46полезный
Написали , что метод machining и выводит информацию о персонале и отправляет почту. Нужно разделить на 2 разных метода.
Нужно переделать
А так вообще не совсем понятно , зачем такое количество параметров в методе? Не проще было создать отдельный класс Employee с нужными полями и передать в метод machining (Employee employee)
Сделать ещё пару методов. Что-то типа такого.
printEmployeeInformation (Employee employee)
sendEmailToEmployee (Employee employee)
machining (Employee employee){
printEmployyeInformation (employee)
sendEmailToEmployee (employee)
}
+1