java tests
java tests
salespeople each receive $200 per week plus 9 percent of their gross
that week. for example, a salesperson who sells $5000 worth of chemicals
gross sale for last week and displays that salesperson's earning.
at a time.
JAVA CODE
package Question.pkg1;
import java.util.Scanner;
grossSales = input.nextDouble();
}
}
QUESTION 2
(The shaded area in the diagram)given the radius of the inner and the
outer circle.
JAVA CODE
package question2;
import java.util.Scanner;
System.out.println("-------------------------------------------------------");
radius1 = mark.nextDouble();
radius2 = mark.nextDouble();
System.out.println("You entered " + radius2 + "cm");
area1 = pi*(radius1*radius1);
area2 = pi*(radius2*radius2);
QUESTION 3
Develop a simple application using switch….case to calculate the area of the following shapes: Square,
Rectangle and Triangle. The user should be able to perform any of the calculation and also press a key to
terminate the program.
JAVA CODE
QUESTION 4 A company has determined that its annual profit is typically 23 percent
total sales. Design a program that asks the user to enter the project
amount of total sales, and then display the profit that will be made
from that amount. Hint. Use the value 0.23 to represent 23 percent.
JAVA CODE
package question4;
import java.util.Scanner;
System.out.println("ANNUAL PROFIT.");
System.out.println("-------------");
totalSales = mark.nextInt();
profit=0.23*totalSales;
QUESTION 5
Develop a simple application using switch….case to calculate the area of the following shapes; Square,
Rectangle and Triangle. The user should be able to perform any of the calculation and also press a key to
terminate the program.
JAVA CODE
QUESTION 6
One acre of land is equivalent to 43,560 square feet. Design a program that asks the user to enter the
total square feet in a tract of land and calculates the number of acres in the tract. Hint: divide the
amount entered by 43,560 to get the number of acres.
JAVA CODE
package question.pkg6;
import java.util.Scanner;
System.out.println("ACRE OF A LAND.");
System.out.println("---------------");
feet = mark.nextDouble();
acre = feet/43560;
QUESTION 7
A customer in a store is purchasing five items. Design a program that asks for the price of each item, and
the display the subtotal of the sales tax, and the total. Assume the sales tax is 6 percent.
JAVA CODE
package question.pkg7;
import java.util.Scanner;
System.out.println("-------------------------------------------");
price1 = mark.nextFloat();
price2= mark.nextFloat();
price3 = mark.nextFloat();
price4 = mark.nextFloat();
price5 = mark.nextFloat();
subTotal = price1+price2+price3+price4+price5;
totalSales = subTotal+tax;
}
}
QUESTION 8
Design a modular program that asks the user to enter a distance in kilometers, and then converts that to
miles. The conversion formula is as follows: miles = kilometers x 0.6214.
JAVA CODE
package question8;
import java.util.Scanner;
System.out.println("-------------------------------");
kilometers = mark.nextDouble();
miles = kilometers*0.6214;
QUESTION 9
Design a program that calculate the total amount of a meal purchased at a restaurant. The program
should ask the user to enter the charge for the food, and then calculate the amount of a 15 percent tip
and 7 percent sales tax. Display each of these amounts and the total.
JAVA CODE
QUESTION 10
Design a program that converts Celsius to Fahrenheit temperature. The formula is as follows: The
program should ask the user to enter a temperature in Celsius, and then display the temperature
converted to Fahrenheit.
JAVA CODE
package question.pkg10;
import java.util.Scanner;
float totalMeal,tip,taxSales,totalSales;
System.out.println("------------------------------------------------");
totalMeal = mark.nextFloat();
}
}
QUESTION 11
Many financial experts advise that property owners should insure their homes or buildings for at least
80 percent of the amount it would cost to replace the structure. Design a modular program that asks the
user to enter the replacement cost of a building and then displays the minimum amount of
insurance he or she should buy for property.
JAVA CODE
package question.pkg11;
import java.util.Scanner;
System.out.println("-----------------------------------");
replacementCost= mark.nextFloat();
QUESTION 12
Design a program that prints the user to enter a number within the range of 1 through 10. The program
should display the Roman numeral version of the number. If the number is outside the range of 1
through 10, the program should display an error message.
JAVA CODE
package question.pkg12;
import java.util.Scanner;
int number;
string roman;
System.out.println("--------------------------------------------------------------");
number = mark.nextInt();
switch(number){
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
System.out.println("Roman Numeral: IX");
break;
case 10:
break;
default:
QUESTION 13
The area of a rectangle is the rectangle’s length times its width. Design a program that asks for the length
and width of two rectangles. The program should tell the user which rectangle has the greater area, or
whether the areas are the same.
JAVA CODE
QUESTION 14
Scientists measure an objects mass in kilograms and its weight in Newton’s. if you know the amount of
mass of an object, in Newtons, with the following formula: weight =mass x 9.8. design a program that
asks the user to enter an objects mass, and then calculates its weight. If the object weighs more than
1000 Newtons, display a message indicating that it is too heavy. If the objects weigh less than 10
Newtons, display a message indicating that it is too light.
JAVA CODE
QUESTION 15
The colors red, blue, and yellow are known as the primary colors because they cannot be made by
mixing other colors. When you mix two primary colors, as shown here: when you mix red and blue, you
get purple. When you mix red and yellow, you get orange. When you mix blue and yellow, you get green.
Design a program that prompts the user to enter the names of two primary colors to mix. If the user
enters anything other than “red”, “blue”, or :yellow” the program should display an error message.
Otherwise, the program should display the name of the secondary color that results.
JAVA CODE
QUESTION 16
Serendipity booksellers has a book club that awards points to its customers based on the number of
books purchased each month. The points are awarded as follows: if a customer purchase 0 books ,
he or she earns 0 points. If a customer purchases 1 book , he or she earns 5 points. If a customer
purchases 2 books , he or she earns 15 points. If a customer purchases 3 books , he or she earns
30 points. If a customer purchases 4 books , he or she earns 60 points. Design a program that asks the
user to enter the number of books that he or she has purchased this month and displays the number
of points awarded.
JAVA CODE
QUESTION 17
The area of a rectangle is calculated according to the following formula: Area = Width x Length. Design a
function that accepts a rectangle’s width and length as arguments and returns the rectangle’s area. Use
the function in a program that prompts the user to enter the rectangle’s width and length, and then
displays the rectangle’s area.
JAVA CODE
QUESTION 18
The Fast Freight Shipping Company charges the following rates: Weight of package Rate per Pound
, 2 pounds or less $1.10 over 2 pounds but not more then 6 pounds $2.20 over 6 pounds
but not more then 10 pounds $3.70 over 10 pounds $3.80. design a program that asks the
user to enter the weight of a package and displays the shipping changes.
JAVA CODE
QUESTION 19
The BMI is often used to determine whether a person with a sedentary lifestyle is overweight or
underweight for his or her height. A person’s BMI calculated with the following formula: Design a
program that calculates and displays a person’s body mass index (BMI) and displays a message indicating
whether the person has optimal weight, is underweight, or is overweight. A sedentary person’s weight is
considered to be optimal if his or er BMI is between 18.5 and 25. If the BMI is less than 18.5, the person
is considered to be underweight. If the BMI value is greater than 25, the person is considered to be
overweight.
JAVA CODE