In: Computer Science
Question 1
Please create three different types of variables and assign three different values into the variables.
Please create a new variable and assign the sum of two variables above.
Please display all the data (four data here) as a line.
Question 2
using Scanner, take three inputs from a user (job level, the number of years in company, and job title) and display yearly bonus percentage based in the following rule:
job level : 1 to 10
Job title : Manager, Developer, QA
job level from 1 to 3: 5%
job level from 4 to 6: 10%
job level from 7 to 10: 15%
if job title is manger, then add 5% more
If an employee spends more than 10 years, then add 5% more.
e.g.
Please type your job level? 3
Please type your job title? Manager
Please type the number of year in Companay? 5
Okay, your bonus rate is 10%
Question 3
From Question 2, if the user types wrong job level, please catch and asking again until the user types the right value.
From Question 2, if the user types wrong job title, please catch and asking again until the user types the right value
Then, display the final bonus rate.
Question 4
Take two numbers with Scanner.
please display sum of all the numbers between two numbers (exclude the start number and the end number) except for odd numbers.
e.g.
Please type a start number: 10
please type an end number: 20
okay, the sum of all the even numbers between 11 and 19 is 60
Q1- Question is not clear as it says in first line to declare 3 variables, and in 2nd line it says to add the two variable declared but we declared three, which is why I don't want to wrong answer, please clear the question in comment section, then I can add the solution for this as well.
Q2-
import java.util.*;
class Main{
public static void main(String args[]){
String position;
int jobLevel,years,bonusRate;
Scanner sc=new Scanner(System.in);
System.out.print("Please type your Job Level(1-10)?: ");
jobLevel=sc.nextInt();
System.out.print("Please type your Job Title(Manager,Developer,QA): ");
position=sc.next();
System.out.print("Please type the Number of years in company: ");
years=sc.nextInt();
if(jobLevel>=1 && jobLevel<=3)
bonusRate=5;
else if(jobLevel>=4 && jobLevel<=6)
bonusRate=10;
else if(jobLevel>=7 && jobLevel<=10)
bonusRate=15;
else
bonusRate=0;
if(position.equalsIgnoreCase("Manager"))
bonusRate+=5;
if(years>10)
bonusRate+=5;
System.out.println("Okay, your bonus rate is "+bonusRate+"%");
}
}
Question 3-
import java.util.*;
class Main{
public static void main(String args[]){
String position;
int jobLevel,years,bonusRate;
Scanner sc=new Scanner(System.in);
do{
System.out.print("Please type your Job Level(1-10)?: ");
jobLevel=sc.nextInt();
}while(jobLevel>10 || jobLevel<=0);
do{
System.out.print("Please type your Job Title(Manager,Developer,QA): ");
position=sc.next();
}while(!(position.equalsIgnoreCase("Manager") || position.equalsIgnoreCase("Developer") || position.equalsIgnoreCase("QA")));
System.out.print("Please type the Number of years in company: ");
years=sc.nextInt();
if(jobLevel>=1 && jobLevel<=3)
bonusRate=5;
else if(jobLevel>=4 && jobLevel<=6)
bonusRate=10;
else if(jobLevel>=7 && jobLevel<=10)
bonusRate=15;
else
bonusRate=0;
if(position.equalsIgnoreCase("Manager"))
bonusRate+=5;
if(years>10)
bonusRate+=5;
System.out.println("Okay, your bonus rate is "+bonusRate+"%");
}
}
Question 4-
import java.util.*;
class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int a,b,sum=0;
System.out.print("Enter start Number: ");
a=sc.nextInt();
System.out.print("Enter end Number: ");
b=sc.nextInt();
for(int i=a+1;i<b;i++){
if(i%2==0)
sum+=i;
}
System.out.println("okay, the sum of all the even numbers between "+(a+1)+" and "+(b-1)+" is "+sum);
}
}
if you like the answer please provide a thumbs up.