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

Hello all! Here are some simple Java Programs...that are giving me trouble pleas

ID: 3625488 • Letter: H

Question

Hello all!

Here are some simple Java Programs...that are giving me trouble please help, I reviewing for an exam...Thanks!

1)Prompt a user to enter the length and width of two rectangles and compute and display the area of
each of the rectangles. The program should then tell the user which rectangle has the greater area, or if the
areas are the same. If the user enters a negative number for length or width, do not compute the area or say
which is the largest. Instead display an error message.

2)Take input of five integers. Find and print the smallest number.

3)One large chemical company either pays its employees by salary, by hourly rate, or by commission
on a weekly basis. Hourly rate workers make time-and-a-half for anything over 40 hours. Commission workers
receive $200 a week plus 9 percent of their gross sales for the week. For example, if a salesperson on commission
sells $5000 worth of chemicals receives $200 plus 9 percent of $5000, or a total of $200 + $450 which $650.
Write code that takes input from a user of either the integer 1 for salaried employees, 2 for hourly rate, or 3 for
commissioned workers. If a one is entered, prompt for a salary. If a two is entered, prompt for hourly wage and
number of hours worked. If a three is entered, prompt for gross amount of sales. In each case, display the
weekly earnings.

If I know there is three problems, if you can only do one please do #3, and if you can do one more please do #1 --- Thanks!!

Explanation / Answer

//Please rate Solution for all the three questions

 

Question 1:Area.java
-------------------------


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Area {


public static void main(String[] args) {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
try{
System.out.println(" Areas of rectangles::: **********************");
System.out.println(" Enter the details of the first rectangle:RECT-1");
System.out.println("Enter length(RECT-1):");
double length1=Double.parseDouble(br.readLine());
if(length1<0){
System.out.println("The value should be positive");
throw new NumberFormatException();
}
System.out.println("Enter width(RECT-1):");
double width1=Double.parseDouble(br.readLine());
if(width1<0){
System.out.println("The value should be positive");
throw new NumberFormatException();
}
if(length1

System.out.println("---->>>>Length is smaller than width so swapping the values:");
double d=length1;
length1=width1;
width1=d;
System.out.println(" Length(RECT-1):"+length1+" Width(RECT-1):"+width1);
}



System.out.println(" Enter the details of the second rectangle:RECT-2");
System.out.println("Enter length(RECT-2):");
double length2=Double.parseDouble(br.readLine());
if(length2<0){
System.out.println("The value should be positive");
throw new NumberFormatException();
}
System.out.println("Enter width(RECT-2):");
double width2=Double.parseDouble(br.readLine());
if(width2<0){
System.out.println("The value should be positive");
throw new NumberFormatException();
}
if(length2System.out.println("---->>>>Length is smaller than width so swapping the values:");
double d=length2;
length2=width2;
width2=d;
System.out.println(" Length(RECT-2):"+length2+" Width(RECT-2):"+width2);
}

double area1=length1*width1;
double area2=length2*width2;
System.out.println("Area of RECT-1(length1*width1):("+length1+"*"+width1+")::"+area1);
System.out.println("Area of RECT-2(length2*width2):("+length2+"*"+width2+")::"+area2);
if(area1>area2){
System.out.println("Area of RECT-1 is greater than Area of RECT-2:::::RECT1>RECT2");
}
else if(area1System.out.println("Area of RECT-2 is greater than Area of RECT-1:::::RECT2>RECT1");
else
System.out.println("Area of RECT-1 is equal to Area of RECT-2:::::RECT1=RECT2 Same area");
}
catch(NumberFormatException e){
//e.printStackTrace();
System.out.println("*********Invalid input********");

}
catch(IOException e){
//e.printStackTrace();
System.out.println("*********Error Reading from keyboard//Enter valid input********");

}
}
}





Question 2:Smallest.java
-----------------------------



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Smallest {


public static void main(String[] args) {
try{
int a[]=new int[5];
int small;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Find the SMALLEST of five integers");
System.out.println("Enter the five integers::");
for(int i=0;i<5;i++){
a[i]=Integer.parseInt(br.readLine());

}
small=a[0];
for(int i=0;i<5;i++){

if(a[i]small=a[i];
}
System.out.println("Smallest Number from("+a[0]+","+a[1]+","+a[2]+","+a[3]+","+a[4]+"):::"+small);

}catch(NumberFormatException e){
//e.printStackTrace();
System.out.println("*********Invalid input********");

}
catch(IOException e){
//e.printStackTrace();
System.out.println("*********Error Reading from keyboard//Enter valid input********");

}
}

}





Question 3:Wages.java
----------------------------




import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Wages {


public static void main(String[] args) {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int choice=0;
double sal;
do{
System.out.println(" WAGES ***** ***** ");
System.out.println("1.salaried employees");
System.out.println("2.Hourly rate Employees");
System.out.println("3.commissioned workers 4.Exit ------------------------");
System.out.println(" Enter your choice from above(1,2 or 3):");
try{
choice=Integer.parseInt(br.readLine());
if(choice==1){
System.out.println("Salary of the employee(weekly):");
sal=Double.parseDouble(br.readLine());
System.out.println("The weekly Earnings is:"+sal);
System.out.println("Enter '0' to exit:");
choice=Integer.parseInt(br.readLine());
}
else if(choice==2){
System.out.println("Salary of Hourly rate employee");
System.out.println(" Hourly Wage:");
sal=Double.parseDouble(br.readLine());
System.out.println("Number of hours worked:");
int hour=Integer.parseInt(br.readLine());
if(hour<=40){
System.out.println("The weekly Earnings is:"+(sal*hour));
}
else{
System.out.println("The weekly Earnings is:"+((sal*hour)+((hour-40)*sal/2)));
}
System.out.println("Enter '0' to exit:");
choice=Integer.parseInt(br.readLine());
}
else if(choice==3){
System.out.println("Salary of Commissioned Workers");
System.out.println(" Gross amount os sales:");
sal=Double.parseDouble(br.readLine());
System.out.println("The weekly Earnings is:"+(200+(0.09*sal)));
System.out.println("Enter '0' to exit:");
choice=Integer.parseInt(br.readLine());
}
else if(choice!=4)
new NumberFormatException();
}
catch(NumberFormatException e){
//e.printStackTrace();
System.out.println("*********Enter valid input********");

}
catch(IOException e){
//e.printStackTrace();
System.out.println("*********Error Reading from keyboard//Enter valid input********");

}
}while(!(choice==4||choice==0));
}

}

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