아래 코드에있는 모든 것을 요구하는 과제가 있습니다. 모든 것이 잘 작동합니다. 160 시간이 넘는 월별 시간을 계산하면 일반 시급의 1.5 배로 지급됩니다. 내 수학은 건전하고 잘 계산됩니다.
((시간-160) * 초과 근무) + (160 * 시간당 요금)
그러나 나는이 if 문을 올바른 방법에 넣는 지 또는 if 문이어야하는지 모르겠습니다. 내 증가 / 감소 지불 방법이이 전에 작동하며 유지되어야합니다. 읽기 쉽도록 몇 가지를 제거했습니다.
HourlyWorker 클래스 :
public class HourlyWorker extends Employee
{
private int hours;
private double hourlyRate;
private double monthlyPay;
private double overtime = (1.5 * hourlyRate);
public HourlyWorker(String last, String first, String ID, double rate)
{
super(last, first, ID);
hourlyRate = rate;
}
public void setHours(int hours)
{
this.hours = hours;
}
public int getHours()
{
return hours;
}
public void setHourlyRate(double rate)
{
this.hourlyRate = rate;
}
public double getHourlyRate()
{
return hourlyRate;
}
public double getMonthlyPay()
{
if (hours > 160)
{
monthlyPay = ((hours - 160) * overtime) + (160 * hourlyRate);
}
else
{
monthlyPay = hourlyRate * hours;
}
return monthlyPay;
}
public void increasePay(double percentage)
{
hourlyRate *= 1 + percentage / 100;
}
public void decreasePay(double percentage)
{
hourlyRate *= 1 - percentage / 100;
}
}
테스트 대상 :
public class TestEmployee2
{
public static void main(String[] args)
{
Employee [] staff = new Employee[3];
HourlyWorker hw1 = new HourlyWorker("Bee", "Busy", "BB1265", 10);
hw1.setHours(200);
staff[0] = hw1;
System.out.println(staff[0].getMonthlyPay());
staff[0].increasePay(10);
System.out.println(staff[0].getMonthlyPay());
}
}
Output is:
1600 (initial monthly rate, with 40 overtime hours and 160 regular hours)
1760 (10% increase to the monthlyPay)
Should be:
2006
22
06.6
@NomadMaker가 언급했듯이 문제는 귀하의 addArtist
방법에 있습니다. 현재 방법 :
public void addArtist(String artistName, String genre)
{
this.artists.add(artist, genre);
}
this.artists
유형의 객체를 저장할 수있는 목록 임을 기억하십시오 Artist
. 따라서 새 매개 변수로 새 아티스트를 만들어야합니다. 다음과 같은 것 :
public void addArtist(String artist, String genre)
{
this.artists.add(new Artist(artist, genre));
}
짐작할 수 있듯이 두 개의 매개 변수 (이름 및 장르를 허용해야 함)를 가진 Artist 생성자가 없습니다 . 따라서이 생성자를 코드에 추가해야합니다.
public Artist(String name, String genre) {
this.name = name;
this.genre = genre;
}
오류 설명 :
artists
목록이며, 호출이 때 무슨 일 this.artist.add(artist, genre)
이 서명이 목록 컬렉션에 속하는 방법 호출 : 인덱스가 (당신을위한 순서가 중요한 경우) 작가를 배치하는 인덱스됩니다.add(int index, Artist artist)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다