0% found this document useful (0 votes)
4 views

java tests

Uploaded by

samiduncan04
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

java tests

Uploaded by

samiduncan04
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

QUESTION 1

one large chemical pays its salespeople on a commission basis. the

salespeople each receive $200 per week plus 9 percent of their gross

that week. for example, a salesperson who sells $5000 worth of chemicals

in a week receives in a week receives$200 plus 9percent of $5000, or a

total of $650. develop a java program that inputs each salesperson's

gross sale for last week and displays that salesperson's earning.

process one salesperson's figure

at a time.

JAVA CODE

package Question.pkg1;

import java.util.Scanner;

* @author KELLY KEKELI

public class Question1 {

public static void main(String[] args) {

double commision, salary, grossSales;

final double pay = 200;

Scanner input = new Scanner(System.in);

System.out.println("Please enter your gross Sales");

grossSales = input.nextDouble();

commision = 0.09 * grossSales;

salary = commision + pay;

System.out.println("Your total earning is GHs" + salary);

}
}

QUESTION 2

Write a program that computes the area of a circular region

(The shaded area in the diagram)given the radius of the inner and the

outer circles, r1 and r0, respectively. we compute the area of the

circular region by subtracting the area of the inner circle of the

outer circle.

JAVA CODE

package question2;

import java.util.Scanner;

* @author KELLY KEKELI

public class Question2 {

public static void main(String[] args) {

double radius1, radius2, area,area1,area2;

final double pi=3.142;

Scanner mark = new Scanner(System.in);

System.out.println("THE AREA OF A CIRCULAR SHADED AREA.");

System.out.println("-------------------------------------------------------");

System.out.println("Enter the inner radius.");

radius1 = mark.nextDouble();

System.out.println("You entered " + radius1 + "cm");

System.out.println("Enter the outer radius.");

radius2 = mark.nextDouble();
System.out.println("You entered " + radius2 + "cm");

area1 = pi*(radius1*radius1);

area2 = pi*(radius2*radius2);

area = area2 -area1;

System.out.println("The area of the circular region is " + area + "cm2");

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;

* @author KELLY KEKELI

public class Question4 {


public static void main(String[] args) {

// TODO code application logic here

double totalSales, profit;

final double percent = 0.23;

Scanner mark = new Scanner(System.in);

System.out.println("ANNUAL PROFIT.");

System.out.println("-------------");

System.out.println("Enter your Total Sales.");

totalSales = mark.nextInt();

profit=0.23*totalSales;

System.out.println("You Annual Profit is " + profit);

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;

* @author KELLY KEKELI

public class Question6 {

public static void main(String[] args) {

double acre, feet;

Scanner mark = new Scanner(System.in);

System.out.println("ACRE OF A LAND.");

System.out.println("---------------");

System.out.println("Enter the total land in Square feet.");

feet = mark.nextDouble();

acre = feet/43560;

System.out.println( feet + " feet is " + acre + "acres");

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;

* @author KELLY KEKELI

public class Question7{


public static void main(String[] args) {

float price1, price2, price3, price4, price5, tax,subTotal, totalSales;

Scanner mark = new Scanner(System.in);

System.out.println("TOTAL PURCHASE PRICE AND TAX OF A CUSTOMER.");

System.out.println("-------------------------------------------");

System.out.println("Please enter your 1st items Price.");

price1 = mark.nextFloat();

System.out.println("Please enter your 2nd items Price.");

price2= mark.nextFloat();

System.out.println("Please enter your 3rd items Price.");

price3 = mark.nextFloat();

System.out.println("Please enter your 4th items Price.");

price4 = mark.nextFloat();

System.out.println("Please enter your 5th items Price.");

price5 = mark.nextFloat();

subTotal = price1+price2+price3+price4+price5;

tax = (float) (0.06*subTotal);

totalSales = subTotal+tax;

System.out.println("Your Subtotal is " + subTotal );

}
}

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;

* @author KELLY KEKELI

public class Question8 {

public static void main(String[] args) {

double kilometers, miles;

Scanner mark = new Scanner(System.in);

System.out.println("CONVERTING KILOMETERS TO MILES.");

System.out.println("-------------------------------");

System.out.println("Please input distance in kilometers here.");

kilometers = mark.nextDouble();

miles = kilometers*0.6214;

System.out.println( kilometers +"km is " + miles + " miles");

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;

* @author KELLY KEKELI

public class Question10 {

public static void main(String[] args) {

float totalMeal,tip,taxSales,totalSales;

Scanner mark = new Scanner(System.in);

System.out.println("MEAL PURCHASE AT A RESTAURANT.");

System.out.println("------------------------------------------------");

System.out.println("Please what is your total meal purchased?");

totalMeal = mark.nextFloat();

tip = (float) (0.15*totalMeal);

taxSales =(float) (0.06*totalMeal);

totalSales = totalMeal + tip + taxSales;

System.out.println("Total Meal: " + totalMeal);

System.out.println("Tip: " + tip);

System.out.println("Tax: " + taxSales);

System.out.println("Total Sales: " + totalSales );

}
}

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;

@author KELLY KEKELI

public class Question11 {

public static void main(String[] args) {

float replacementCost, minInsurance;

Scanner mark = new Scanner(System.in);

System.out.println("INSURANCE COST ON MINIMUM PROPERTY.");

System.out.println("-----------------------------------");

System.out.println("Please what is your building 🏛 replacement cost");

replacementCost= mark.nextFloat();

minInsurance= (float) (0.8*replacementCost);

System.out.println("It will be great to get at least " +minInsurance +

" Insurance for your property" );


}

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;

* @author KELLY KEKELI

public class Question12 {

public static void main(String[] args) {

int number;

string roman;

Scanner mark = new Scanner(System.in);

System.out.println("CONVERTING NUMBER TO ROMAN NUMERAL.");

System.out.println("--------------------------------------------------------------");

System.out.println("Please input a number from 1 - 10");

number = mark.nextInt();

switch(number){

case 1:

System.out.println("Roman Numeral: I");

break;
case 2:

System.out.println("Roman Numeral: II");

break;

case 3:

System.out.println("Roman Numeral: III");

break;

case 4:

System.out.println("Roman Numeral: IV");

break;

case 5:

System.out.println("Roman Numeral: V");

break;

case 6:

System.out.println("Roman Numeral: VI");

break;

case 7:

System.out.println("Roman Numeral: VII");

break;

case 8:

System.out.println("Roman Numeral: VIII");

break;

case 9:
System.out.println("Roman Numeral: IX");

break;

case 10:

System.out.println("Roman Numeral: X");

break;

default:

System.out.println("Error, Please enter a number between 1 and 10");

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

You might also like