Professional Documents
Culture Documents
Compilation (Zean)
Compilation (Zean)
Calculate and
print the thickness (T) of the wall of the pipe.
import java.util.Scanner;
public class Pipe_Prob1_Encarnacion {
public static void main(String[] args) {
//setup the program to be ready for keyboard input
Scanner ENCARNACION = new Scanner (System.in);
System.out.print("Enter the outside diameter: ");
double Out_Dia = ENCARNACION.nextInt();
System.out.print("Enter the inside diameter: ");
double In_Dia = ENCARNACION.nextInt();
//formula
double z = (Out_Dia - In_Dia)/2;
System.out.println("The thickness of the pipe is "+z );
}
}
2. Read a temperature in degrees Fahrenheit, output in degrees Centigrade.
F= (9/5) * C + 32.
import java.util.Scanner;
public class Temp_Prob2_ENCARNACION {
}
}
3. Read an angle expressed in degrees, minutes and seconds, output in radians.
import java.util.Scanner;
public class ANGLE_ENCARNACION {
//input
//formula
}
}
4. Read current (I_AMP) flowing through a cable and the resistance (R_OHM) of the cable,
compute and output the power loss (P_WATT) through the cable.
P_WATT = R_OHM* I_AMP* I_AMP
import java.util.Scanner;
}
5. A box contains Philippine coins. How much money is in the box?
Assume: N1 10.00 coin
N2 P5.00 coin.
N3 P1.00 coin
N4 25 centavo coin
N5 10 centavo coin
N6 5 centavo coin.
import java.util.Scanner;
public class COINS_ENCARNACION {
//formula
System.out.println("");
double Sum =((P10*10)+(P5*5)+(P1*1)+(c25*0.25)+(c10*0.10)+(c5*0.05));
System.out.print("Total amount of coins: P"+Sum);
}
}
6. An electrical wire supplier sells wire in 500-foot rolls, 300 foot rolls, and 100 foot rolls
and the number of feet additional wire to be given to the customer.
import java.util.Scanner;
public class WIRE_ENCARNACION {
public static void main(String[] args) {
//formula
//output
import java.util.Scanner;
public class CHANGE_ENCARNACION {
public static void main(String[] args) {
import java.util.Scanner;
public class TRIANGLE_ENCARNACION {
//formula
double s = (a+b+c)/2;
double A = Math.sqrt(s*(s-a)*(s-b)*(s-c));
double Insc = A/s;
double Circ = (a*b*c)/(4*A);
double R_Insc = Math.PI*Math.pow(Insc,2);
double R_Circ = Math.PI*Math.pow(Circ,2);
//output
System.out.println("");
System.out.println("Area of the Triangle: "+A);
System.out.println("Area of Inscribed Circle: "+R_Insc);
System.out.println("Area of Circumscribed circle "+R_Circ);
}
}
1) ParkingFee( Use if )
Parking charge per hour at SMBC underground parking is as follows:
P 35.00 - minimum charge for 4 hours parking or less,
P 15.00/hr. - additional charge in excess of 4 hours parking,
P 250.00- maximum charge.
Create a java program that reads the number of hours a vehicle was parked. Calculate and output the
parking charge.
(Note: Inputs should be integers only)
Depicted below are sample outputs when the program is executed (the items in red bold characters are inputted by the user,
while the items in blue bold characters are calculated and outputted by the program):
import java.util.Scanner;
public class PARKINGFEE_ENCARNACION {
public static void main(String[] args) {
if(hours >= 8)
{
double MaxChar = 250;
System.out.print("Parking Fee: P"+MaxChar);
}
else
if(hours > 4)
{
double ExceChar = (((hours - 4)*15)+35);
System.out.print("Parking Fee: P"+ExceChar);
}
else
if(hours<=4)
{
double Fee = 35;
System.out.print("Parking Fee: P"+Fee);
}
else
{
System.out.print("Invalid Input");
}
}
}
2) CommodityCode (Use Switch)
A certain store has the following scheme:
Commodity Code:
A - commodities are discounted by 15%
B - commodities are taxed by 12%
C - commodities are charged as priced
Create a program that reads a commodity code, quantity of the commodities bought and
the unit price and output the amount to be paid by the customer.
Depicted below are sample outputs when the program is executed (the items in red bold characters are inputted by the user, while the items in
blue bold characters are calculated and outputted by the program):
import java.util.*;
public class COMMODITYCODE_ENCARNACION {
T = Qn*Pr;
Dc = T*0.15;
Tp = T-Dc;
case 'B':
System.out.print("Enter Quatitity of commodity: ");
Qn = Encarnacion.nextDouble();
System.out.print("Enter unit price: ");
Pr = Encarnacion.nextDouble();
T = Qn*Pr;
Tx = T*0.12;
Tp = T+Tx;
case 'C':
System.out.print("Enter Quatitity of commodity: ");
Qn = Encarnacion.nextDouble();
System.out.print("Enter unit price: ");
Pr = Encarnacion.nextDouble();
Tp = Qn* Pr;
default:
System.out.println("Invalid Code");
break;
}
}
}
3) Reverse (Use the do-while Loop 20pts)
Create a java program that reads a number (NUM) and determine its reverse by using the
division and remainder/modulo operators. If the last digit is zero, replace it with a one(1) before
reversing the number. Output also the sum of all the digits.
Depicted below are sample outputs when the program is executed (the items in red bold characters are
inputted by the user, while the items in blue bold characters are calculated and outputted by the
program):
import java.util.Scanner;
public class REVERSEJAVA_ENCARNACION {
int a, r = 0, s = 0;
System.out.print("Enter a number: ");
int n = Encarnacion.nextInt();
a= n%10;
if(a==0)
{
n = n+1;
}
do
{
a = n%10;
r = r*10+a;
s = s+a;
n = n/10;
}
while(n>0);
System.out.println("The reverse order is: "+r);
System.out.println("The sum is: "+s);
}
}
4) Series1 (Use the while Loop 20pts)
int n = 1;
double sum = 0.0;
while(sum<=3.1)
{
sum += 1.0/n;
System.out.printf("\n@n \t=%2d, %10.4f",n,sum);
n++;
}
System.out.printf("\nTherefore, the number of terms before s exceeds 3.1 is %2d",n-2);
}
}
5) Equation.java - (Use the for Loop 20pts)
Using the equation Y=2+4X-X, create a java program that will compute and display the values of Y for
the values of X from 1 to 20 in increments of 1 without using an array.
Depicted below is a sample output when the program is executed:
double y;