0% found this document useful (0 votes)
2 views8 pages

Temperature and Salary Conversion Algorithms

The document presents 8 programming exercises in Java that involve basic concepts of sequential structure such as data input and output, mathematical operations, variable declaration, and the use of formulas. Each exercise describes a mathematical problem and provides the pseudocode of the solution implemented as a sequential algorithm in Java.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

Temperature and Salary Conversion Algorithms

The document presents 8 programming exercises in Java that involve basic concepts of sequential structure such as data input and output, mathematical operations, variable declaration, and the use of formulas. Each exercise describes a mathematical problem and provides the pseudocode of the solution implemented as a sequential algorithm in Java.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

EXERCISE I:

1. Design an algorithm to convert sexagesimal degrees (S) to


centigrade degrees (C) and radians (R). Consider the following
formulas:
C = 200x S / 180

R = 3.1416 x S / 180

The resolution would be as follows:


}
protected void actionPerformedBtnConvert(ActionEvent arg0) {
CODE OF MY BUTTON
//DECLARE VARIABLES
double centi, sexa, radian;
DATA INPUT
sexa = [Link]([Link]());
//PROCESS
(200 * sexa) / 180;
(3.1416 * sexa) / 180;
//DATA OUTPUT
Equivalent temperatures:
Temperature in degrees Celsius:
Temperature in radians:
}

EXERCISE II:
Write an algorithm that reads a temperature in degrees Celsius (C) and the
convert it to its equivalents in degrees Fahrenheit (F), degrees Kelvin (K) and
Rankine degrees (R). Use the following formulas:

Rankine = Celsius + 460

(9*centigrados/5)+32

Kelvin = Rankine - 187

The resolution would be as follows:


}
protected void actionPerformedBtnProcesar(ActionEvent arg0) {
//DECLARE VARIABLES
double centi, fah, kel, rank;
//DATA INPUT
centi=[Link]([Link]());
//PROCESS
centi+460
fah=(9*centi/5)+32;
rank-187
OUTPUT OF DATA
Equivalent temperatures:
Temperature in Rankine:
Temperature in Fahrenheit:
Temperature in Kelvin:
}
protected void actionPerformedBtnDelete(ActionEvent arg0) {
DRAFT BUTTON

translatedText
[Link]();
}
}

EXERCISE III
To estimate a child's weight in pediatric emergency situations, one should
use the following formula:

weight in kilograms = 3 x age in years + 7

The solution is as follows:

protected void actionPerformedBtnProcess(ActionEvent arg0) {


//DECLARE VARIABLES
int age;
double peso;
DATA INPUT
[Link]([Link]());
Process
weight=3*age+7;
//DATA OUTPUT

The estimated weight of the child is:


}

EXERCISE IV:
A hospital has received a special donation that will be distributed among the
áreas de Pediatría, Medicina General, Ginecología y Traumatología. Cada área
will receive a part of the donation equivalent to:

Pediatrics: 20% of the total amount received among General Medicine


and Gynecology.
General Medicine: 45% of the donation.
Gynecology: 80% of the amount received by General Medicine.
Traumatology: what remains after donation.
Design an algorithm that determines how much each area will receive

The solution would be the following:


}
protected void actionPerformedBtnProcess(ActionEvent arg0) {
double don, ped, med, gine, tra;
don=[Link]([Link]());
med=0.45*don;
gine = .80 * med;
ped=0.20*(med+gine);
tra=don-(med+gine+ped);
The donation will be distributed as follows:
For general medicine:
For gynecology:
For pediatrics:
For traumatology:
}

EXERCISE V:
A company manufactures standard size polo shirts applying a discount.
11.5% of the purchase amount.

The amount of the purchase is calculated by multiplying the price of the polo by the
number of polos acquired.

The amount to be paid is calculated by subtracting the purchase amount from the amount of
discount.

Additionally, the company offers two pens for each polo purchased.

Given the price of the polo and the quantity of polos purchased, design an algorithm.
that determines the purchase amount, the discount amount, the amount to
pay and the number of gift pens that correspond to a customer.

The resolution would be as follows:


}
protected void actionPerformedBtnProcesar(ActionEvent arg0) {
//MY CODE
int cant, gift;
double prec, icom, ides, ipag;
//DATA ENTRY
cant=[Link]([Link]());
prec=[Link]([Link]());
PROCESS
icom=prec*cant;
0.115*icom;
ipag=icom-ides;
2*cant;
//DATA OUTPUT

The amount of the purchase is:


The amount of the discount is:
The amount to be paid is:
Number of pens as a gift:
}

And if I add a delete button and close window:


}
protected void actionPerformedBtnDelete(ActionEvent arg0) {
//CODE DELETE
translatedText
[Link]("");
[Link]("");
[Link]();
}
protected void actionPerformedBtnClose(ActionEvent arg0) {
CLOSE CODE
dispose();
}
}

EXERCISE VI:
A company has decided to grant a bonus to its employees for the only time.
The bonus will consist of the sum of a bonus for children
plus a bonus for length of service. The bonus for children will be equal
S/. 25 for each child. The service time bonus will be equal to S/. 50
for each year of service. Given the number of children and the number of
years of service, design an algorithm that determines the amount of the
bonus for children, the amount of the service time bonus and the
total bonus amount due to an employee.

The resolution would be as follows:


protected void actionPerformedBtnProcess(ActionEvent e) {
//MY CODE
//DECLARE VARIABLES
int children, time;
double bh,bts,ibt;
DATA READING
children=[Link]([Link]());
time=[Link]([Link]());
PROCESS
bh=25*children;
bts=50*time;
ibt=bh+bts;
DATA OUTPUT
[Link]("");
You are entitled to the following bonus for children:
The following bonus for length of service corresponds:
+bts+
Your total bonus is:
}
protected void actionPerformedBtnDelete(ActionEvent e) {
translatedText
[Link]
[Link]("");
[Link]();
}
protected void actionPerformedBtnClose(ActionEvent e) {
CLOSE
dispose();
}
}

EXERCISE VII:
A company pays its employees a gross salary that is equal to the sum of
a basic salary plus a commission. The basic salary is equal to S/. 350. The
commission is equal to 8% of the amount sold in the month. The legal discount is
equal to 15% of the gross salary. The net salary is equal to the gross salary minus
minus the discount. Given the amount sold for the month, design an algorithm that
determine the basic salary, the commission, the gross salary, the deduction and the
net salary of an employee of the company.

The resolution would be as follows:


}
protected void actionPerformedBtnProcess(ActionEvent arg0) {
//PROCESS
//DECLARE VARIABLES
int sales;
double suba, comi, subru, desc, sune;
//DATA INPUT
sales = [Link]([Link]());
PROCESS
suba=350;
comi=0.08*sales;
suba+comi
0.15*subru;
subru-desc
DATA OUTPUT

Gross salary:
Commission:
Discount:
Net salary:
}
protected void actionPerformedBtnDelete(ActionEvent arg0) {
//DELETE

[Link]("");
[Link]();
}
}

EXERCISE VIII:
A store has put shirts on sale offering a double
12% discount. The purchase amount is equal to the product of the price of the
shirt for the number of shirts purchased. The first discount is equal to the
12% of the purchase amount. The second discount is equal to 12% of the
subtract the amount of the purchase minus the first discount. The amount of
The total discount is equal to the sum of the first and second discount. The amount
the amount to be paid is equal to the purchase amount minus the discount amount
total. Given the price of the shirt and the quantity of shirts purchased, design
an algorithm that determines the purchase amount, the total discount amount and
the amount to be paid corresponding to a client.

The resolution would be as follows:


//DEC VARIABLES
int cant;
double pre, icom, desc1, desc2, desto, ipag;
//DATA INPUT
pre=[Link]([Link]());
cant=[Link]([Link]());
//PROCESS
icom= pre*cant;
0.12*icom;
0.12 * (icom - desc1);
desto=desc1+desc2;
icom-desto
//DATA OUTPUT
translatedText
Purchase amount:
Total discount amount:
Amount to be paid:
}
protected void actionPerformedBtnDelete(ActionEvent e) {

[Link]("");
[Link]("");
[Link]();
}
protected void actionPerformedBtnClose(ActionEvent e) {
dispose();
}
}
Java Basic Exercises Sequential Structure
Relationship No. 2: Exercises 4, 5, 6, and 7

Exercise 4:
Program that reads a number of degrees Celsius and converts it to degrees.
Fahrenheit.
The corresponding formula to convert from Celsius to Fahrenheit is:
F = 32 + (9 * C / 5)
import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
double gradosC, gradosF;
[Link]("Introduce degrees Celsius:");
degreesC = [Link]();
degreesF = 32 + (9 * degreesC / 5);
[Link](gradosC + " ºC = " + gradosF + " ºF");
}
}

Exercise 5. Program that reads the value of the radius of a circle from the keyboard and
calculate and display on screen the length and area of the circumference.

Circumference length = 2*PI*Radius

import [Link].*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
double radius, longitude, area;
[Link]("Enter the radius of the circumference:");
[Link]();
length = 2 * [Link] * radius;
area = [Link] * [Link](radius, 2);
[Link]("Length of the circumference -> " + length);
[Link]("Area of the circle -> " + area);
}
}
Program that allows entering 12 values and shows how many are positive and how many are negative.
negatives and how many null

import [Link];

public class Main {

public static void main(String[] args) {


Scanner data = new Scanner([Link]);

int []x;
x = new int[12];
int positivos=0,negativos=0,nulos=0;
for(int i=0; i > 0)
positives++;
}
for(int i=0; i<[Link]; i++)
{
if(x[i]<0)
{
negatives++;
}
}
for(int i=0; i<[Link];i++){
if(x[i]==0){
null++;
}
}
The number of positive numbers is
The number of negative numbers is
negatives)
The number of null values is
}
}

You might also like