Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Electronically submit source code (files ended with .java) to blackboard. In ecl

ID: 3883005 • Letter: E

Question

Electronically submit source code (files ended with .java) to blackboard. In eclipse of Windows, if you have not changed the default workspace, eclipse projects are in c:Usersyour_user_nameworkspace.

Problem 1. RightTriangle.java (right triangle) Write a program to enter the two sides, a and b, of a right triangle from keyboard, calculate its area and perimeter.

The area is defined as ½ ab.

The perimeter is defined as the sum of three edges: two sides plus the hypotenuse.

Print out the area and perimeter of this right triangle.

Problem 2. Time.java (represent minutes in days, hours, and minutes). Write a method to take time in minutes, then represent the time by days, hours, and minutes. For example, given 10000 minutes, we get 6 days 22 hours 40 minutes. (Hint: 10000 minutes = 166 hours 40 minutes, where 166 hours can be represented by 6 days 22 hours).

Problem 3. Tax.java (calculate income tax) Suppose we charge tax as the following table.

Income

Tax rate

[0, 1000), that is, income is less than 1000

0% (no tax)

[1000, 5000), that is, income is at least 1000 but no more than 5000

10%

5000 and above

20%

Take an income entered from keyboard, and calculate the tax and print it out.

Income

Tax rate

[0, 1000), that is, income is less than 1000

0% (no tax)

[1000, 5000), that is, income is at least 1000 but no more than 5000

10%

5000 and above

20%

Va2 + f?

Explanation / Answer

RightTriangle.java

import java.util.Scanner;

public class RightTriangle {

public static void main(String[] args) {

//Declaring variables

int a, b;

double area, perimeter, hypotenuse;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

//Getting the input entered by the user

System.out.print("Enter the side 'a' :");

a = sc.nextInt();

System.out.print("Enter the side 'b' :");

b = sc.nextInt();

area = 0.5 * a * b;

hypotenuse = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));

perimeter = a + b + hypotenuse;

//Displaying the output

System.out.println("Area of the Triangle :" + area);

System.out.println("Perimeter of the Triangle :" + perimeter);

}

}

_________________

Output:

Enter the side 'a' :3
Enter the side 'b' :4
Area of the Triangle :6.0
Perimeter of the Triangle :12.0

_______________

Problem 2:

Time.java

import java.util.Scanner;

public class Time {

public static void main(String[] args) {
//Declaring variables
int totMins, hours, minutes, seconds;

//Scanner class Object is used to read the inputs entered by the user
Scanner sc = new Scanner(System.in);

//getting the number of seconds entered by the user
System.out.print(" Enter No of Minutes :");
totMins = sc.nextInt();

//calling the method secondTime() by passing the seconds as arguments
toDaysHoursMins(totMins);
}
/*This method will converts the minutes to days,hours,minutes
* Params:total minutes
* Return:String
*/
private static void toDaysHoursMins(int totMins) {

//Declaring variable
int days, hours, minutes;

//calculating the number of days
days = totMins / 1440;
totMins = totMins - (days * 1440);

//calculating the number of hours
hours = totMins / 60;
totMins = totMins - (hours * 60);

//calculating the number of minutes
minutes = totMins;

//displaying the total seconds to hours,minutes,seconds
if (days > 0)
System.out.print(days + " days ");
if (hours > 0)
System.out.print(hours + " hours ");
if (minutes > 0)
System.out.print(minutes + " minutes");


}

}

____________________

Output:


Enter No of Minutes :10000
6 days 22 hours 40 minutes

_____________________

Problem 3:

package org.students;

import java.util.Scanner;

public class Tax {

public static void main(String[] args) {

//Declaring variables

int income;

double tax = 0;

/*

* Creating an Scanner class object which is used to get the inputs

* entered by the user

*/

Scanner sc = new Scanner(System.in);

//Getting the input enetred by the user

System.out.print("Enter the Income ;");

income=sc.nextInt();

//based on the input income the corresponding block of code will be executed.

if(income>=0 && income<1000)

{

tax=0.0;   

}

else if(income>=1000 && income<5000)

{

tax=income*0.10;

}

else if(income>=5000)

{

tax=income*0.20;

}

//Displaying the output

System.out.println("The Amount of Tax is :"+tax);

}

}

_______________________

Output:

Enter the Income ;4000
The Amount of Tax is :400.0

_____________Could you rate me well.Plz .Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote