Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 20

1. Input the outside and the inside diameter (IN_DIA, OUT_DIA) of a pipe.

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 {

public static void main(String[] args) {

// TODO, add your application code


Scanner ENCARNACION = new Scanner(System.in);
System.out.print("Enter Temperature \u00b0F: ");

double Fah = ENCARNACION.nextDouble();


double Cel = ((Fah-32)*5/9);

System.out.println("Temperature in Centigrade is "+Cel);

}
}
3. Read an angle expressed in degrees, minutes and seconds, output in radians.

import java.util.Scanner;
public class ANGLE_ENCARNACION {

public static void main(String[] args) {

Scanner Encarnacion = new Scanner (System.in);

//input

System.out.print("Enter Angle in degrees: ");


double Deg = Encarnacion.nextDouble();

System.out.print(" minutes: ");


double Min = Encarnacion.nextDouble();

System.out.print(" seconds: ");


double Sec = Encarnacion.nextDouble();

//formula

double RAD =(((Deg+(Min/60)+(Sec/3600))/180)*3.145926);


System.out.print("Converted value is equal to: " +RAD+ " rad.");

}
}
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;

public class WATT_ENCARNACION {

public static void main(String[] args) {

Scanner Encarnacion = new Scanner (System.in);

System.out.print("Enter Current: ");

double AMP = Encarnacion.nextDouble();

System.out.print("Enter Resistance: ");

double OHM = Encarnacion.nextDouble();

double WATT = OHM*AMP*AMP;

System.out.print("Total power loss is: " +WATT+ " watts")

}
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 {

public static void main(String[] args) {


Scanner Encarnacion = new Scanner (System.in);

System.out.print("Enter number of P10 coins: ");


double P10 = Encarnacion.nextDouble();

System.out.print("Enter number of P5 coins: ");


double P5 = Encarnacion.nextDouble();

System.out.print("Enter number of P1 coins: ");


double P1 = Encarnacion.nextDouble();

System.out.print("Enter number of c25 coins: ");


double c25 = Encarnacion.nextDouble();

System.out.print("Enter number of c10 coins: ");


double c10 = Encarnacion.nextDouble();

System.out.print("Enter number of c5 coins: ");


double c5 = Encarnacion.nextDouble();

//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) {

Scanner Encarnacion = new Scanner (System.in);


System.out.print("Enter length of wire needed by customer: ");
int length = Encarnacion.nextInt();
System.out.println(+length+" feet requires: ");

//formula

int x500 = length/500;


int x300 = length%500/300;
int x100 = length%500%300/100;
int add = length%500%300%100;

//output

System.out.println("\t 500 foot roll(s) -"+x500);


System.out.println("\t 300 foot roll(s) -"+x300);
System.out.println("\t 100 foot roll(s) -"+x100);
System.out.println("\t additional foot roll(s) -"+add);
}
}
7. Input the amount of purchase which is less than P1000.00. Calculate the change of
P1000.00 given by the customer with the following breakdown:
P 500 - _______________;
P 200 - _______________;
P100 - _______________;
P 50.00 - _______________;
P 20.00 - _______________;
P 10.00 - _______________;
P 5.00 - _______________;
P 1.00 - _______________;

import java.util.Scanner;
public class CHANGE_ENCARNACION {
public static void main(String[] args) {

Scanner Encarnacion = new Scanner (System.in);


System.out.print("Enter the amount of purchase: ");
int Amount = Encarnacion.nextInt();
if(Amount<=1000)
{
int Change = 1000-Amount;
System.out.println("\t\t\t\t change: "+Change);

int x500 = Change/500;


int x200 = Change%500/200;
int x100 = Change%500%200/100;
int x50 = Change%500%200%100/50;
int x20 = Change%500%200%100%50/20;
int x10 = Change%500%200%100%50%20/10;
int x5 = Change%500%200%100%50%20%10/5;
int x1 = Change%500%200%100%50%20%10%5/1;

System.out.println("\t P500 - "+x500);


System.out.println("\t P200 - "+x200);
System.out.println("\t P100 - "+x100);
System.out.println("\t P50 - "+x50);
System.out.println("\t P20 - "+x20);
System.out.println("\t P10 - "+x10);
System.out.println("\t P5 - "+x5);
System.out.println("\t P1 - "+x1);
}
else
{
System.out.print("Invalid Input");
}
}
8. Calculate the area of the triangle, the area of the largest inscribed circle, and the area of
the smallest circumscribed circle given a value for a, b and c.

import java.util.Scanner;
public class TRIANGLE_ENCARNACION {

public static void main(String[] args) {

Scanner Encarnacion = new Scanner (System.in);

System.out.print("Enter value of side a: ");


double a = Encarnacion.nextDouble();

System.out.print("Enter value of side b: ");


double b = Encarnacion.nextDouble();

System.out.print("Enter value of side c: ");


double c = Encarnacion.nextDouble();

//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) {

Scanner Encarnacion = new Scanner(System.in);

System.out.print("Enter number of hours: ");


int hours = Encarnacion.nextInt();

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 {

public static void main(String[] args) {

Scanner Encarnacion = new Scanner (System.in);


double Qn , Pr , Tp ,Dc , T , Tx;

System.out.print("Enter Commodity Code: ");


char code = Encarnacion.next().charAt(0);
switch (code)
{
case 'A':
System.out.print("Enter Quatitity of commodity: ");
Qn = Encarnacion.nextDouble();
System.out.print("Enter unit price: ");
Pr = Encarnacion.nextDouble();

T = Qn*Pr;
Dc = T*0.15;
Tp = T-Dc;

System.out.print("The amount to be paid: "+Tp);


break;

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;

System.out.print("The amount to be paid: "+Tp);


break;

case 'C':
System.out.print("Enter Quatitity of commodity: ");
Qn = Encarnacion.nextDouble();
System.out.print("Enter unit price: ");
Pr = Encarnacion.nextDouble();

Tp = Qn* Pr;

System.out.print("The amount to be paid: "+Tp);


break;

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 {

public static void main(String[] args) {

Scanner Encarnacion = new Scanner (System.in);

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)

The value of S is computed from the formula:


S = 1/1 + 1/2 + 1/3 + 1/4 + 1/5 + … + 1/N
Without using a user-defined method, create a program to output the number of terms required and the
value of S before S exceeds 3.1.
Example: 1st term: S = 1;
2nd term: S = 1 + 1/2 = 1.5;
3rd term: S = 1 + 1/2 + 1/3 = 1.8333;
4th term: S = 1 + 1/2 + 1/3 + 1/4 = 2.08333;
5th term: S = 1 + 1/2 + 1/3 + 1/4 + 1/5 = 2.2833;
...
nth term: S = ?

public class SERIES1_ENCARNACION {

public static void main(String[] args) {

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:

public class EQUATION_ENCARNACION {

public static void main(String[] args) {

double y;

System.out.println("X values Y values");


for(int x = 1; x<=20;x++)
{
y=2+(4*x)-(Math.pow(x,2));
System.out.printf("\n %4d \t %8.2f",x,y);
}

You might also like