Write a class and a Java program to use the class. Part 1. Create a class called
ID: 3843120 • Letter: W
Question
Write a class and a Java program to use the class. Part 1. Create a class called Income that contains the following: 1. Two (2) instance variables a double called "IncomeYTD" and double called "hourlyRate" The class should also include the following methods: 2. a constructor that receives 2 double parameters; the constructor will use these parameters to initialize the incomeYTD and the hourlyRato respectively. 3. setincomeYTD: it receives a double parameter and assigns it to the incomeYTD. 4. getincomeYTD: it returns the incomeYTD value 5. calculatelncome it receives a double parameter and calculates and returns the current income amount for the current hourly rate (income = hourlyRate times workingHours)Explanation / Answer
import java.io.*;
public class Income {
private double incomeYTD;
private double hourlyRate;
Income(double incYTD, double hrrate){
incomeYTD = incYTD;
hourlyRate = hrrate;
}
public void setIncomeYTD(double value){
incomeYTD = value;
}
public double getIncomeYTD(){
return incomeYTD;
}
public double calculateincome(double workinghours){
return hourlyRate * workinghours;
}
}
public class Demo {
public static void main(String args[]){
Income inc = new Income(20000.0, 100.0);
System.out.println(inc.getIncomeYTD());
inc.setIncomeYTD(21000.0);
System.out.println(inc.getIncomeYTD());
System.out.println(inc.calculateincome(1000.5));
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.