HABBILING, Reniel M
HABBILING, Reniel M
System.out.print("Enter y: ");
int y = reniel.nextInt();
System.out.print("Enter z: ");
int z = reniel.nextInt();
int HN,MN,LN;
if(x>y&&y>z){
HN = x;
MN = y;
LN = z;
System.out.printf("Highest number: %d",HN);
System.out.printf("\nDescending Order: %d %d
%d",HN,MN,LN);
}
else
if(x>z&&z>y){
HN = x;
MN = z;
LN = y;
System.out.printf("Highest number: %d",HN);
System.out.printf("\nMiddle number: %d",MN);
System.out.printf("\nLowest number: %d",LN);
System.out.printf("\nAscending Order: %d %d %d",LN,MN,HN);
System.out.printf("\nDescending Order: %d %d %d",HN,MN,LN);
}
else
if(y>x&&x>z){
HN = y;
MN = x;
LN = z;
System.out.printf("Highest number: %d",HN);
System.out.printf("\nMiddle number: %d",MN);
System.out.printf("\nLowest number: %d",LN);
System.out.printf("\nAscending Order: %d %d %d",LN,MN,HN);
System.out.printf("\nDescending Order: %d %d %d",HN,MN,LN);
}
else
if(y>x&&x>z){
HN = y;
MN = x;
LN = z;
System.out.printf("Highest number: %d",HN);
System.out.printf("\nMiddle number: %d",MN);
System.out.printf("\nLowest number: %d",LN);
System.out.printf("\nAscending Order: %d %d %d",LN,MN,HN);
System.out.printf("\nDescending Order: %d %d %d",HN,MN,LN);
}
else
if(y>z&&z>x){
HN = y;
MN = x;
LN = z;
System.out.printf("Highest number: %d",HN);
System.out.printf("\nMiddle number: %d",MN);
System.out.printf("\nLowest number: %d",LN);
System.out.printf("\nAscending Order: %d %d %d",LN,MN,HN);
System.out.printf("\nDescending Order: %d %d %d",HN,MN,LN);
}
System.out.print("\nOdd Number(s): ");
if(x%2==1){
System.out.print(x+" ");
}
if(y%2==1){
System.out.print(y+" ");
}
if(z%2==1){
System.out.print(z);
}
int sum = x + y + z;
double ave = (double)sum/3;
System.out.println("\nThe sum is "+sum);
System.out.printf("The average is %5.2f",ave);
}
}
3. A leap year is a year divisible by 4 unless it is a century year, in which case it must be divisible by 100. Read a
year and output a message whether the year is a leap year, century year or otherwise.
public class Prob13_Year_HABBILING {
public static void main(String[] args) {
System.out.print("Enter Year: ");
int yr = Keyboard.readInt();
if(yr%4==0){
if(yr%100==0){
System.out.print("Century Year");
}
else
System.out.print("Leap Year");
}
else
System.out.print("Regular Year");
}
}
4. A professor converts numeric grades to letter grades in the following way:
93 – 99 Excellent
87 – 92 Very Good
80 – 86 Good
70 – 79 Fair
65 - 69 Poor
Read a numeric grade and output the equivalent description.
public class Prob15_Grades_HABBILING {
public static void main(String[] args) {
System.out.print("Enter Grade: ");
double gr = Keyboard.readDouble();
if(gr>=93&&gr<=99){
System.out.println("EXCELLENT");
}
else
if(gr>=87&&gr<=92){
System.out.println("VERY GOOD");
}
else
if(gr>=80&&gr<=86){
System.out.println("GOOD");
}
else
if(gr>=70&&gr<=79){
System.out.println("FAIR");
}
else
if(gr>=65&&gr<=69){
System.out.println("POOR");
}
else
System.out.println("INVALID Grade");
}
}
6. A telephone area code is a three digit number. The first of which is either 1 or 9, the second is any number among
5, 6, 7, 8, and 9. The third digit is any non zero number. Read a three digit number and checks to see if it is a valid
code. Output a message saying so.
public class Prob19_TelephoneCode_HABBILING {
public static void main(String[] args) {
System.out.print("Enter Telephone Area Code: ");
int num = Keyboard.readInt();
int a = num/100;
int b = (num%100)/10;
int c = (num%100)%10;
if(num<=999){
if(a==1||a==9){
if(b>4&&b<10){
System.out.println("VALID
Telephone Code");
}
else
7. The ABC Electric Company bases its electricity charges on two rates. Customers are charged P 30.117 per
kilowatt-hour (KWH) for the first 400 KWH used in a month, and P25.23 for all KWH used thereafter. Read in
the consumption and output amount to be charged to the customer.
public class Prob21_Electricity_HABBILING {
public static void main(String[] args) {
System.out.print("Enter consumption in KWH: ");
double KWH = Keyboard.readDouble();
if(KWH<=400){
double Ch = 30.117*KWH;
System.out.printf("Amount Charged: %.2f",Ch);
}
else{
double Ch = (30.117*400)+(25.23*(KWH-400));
System.out.printf("Amount Charged: %2f",Ch);
}
}
}
9.
public class Prob15_Grade_Switch_HABBILING {
public static void main(String[] args) {
System.out.print("Enter Grade: ");
int gr = Keyboard.readInt();
switch(gr){
case 65:
case 66:
case 67:
case 68:
case 69:
System.out.println("POOR");
break;
case 70:
case 71:
case 72:
case 73:
case 74:
case 75:
case 76:
case 77:
case 78:
case 79:
System.out.println("FAIR");
break;
case 80:
case 81:
case 82:
case 83:
case 84:
case 85:
case 86:
System.out.println("GOOD");
break;
case 87:
case 88:
case 89:
case 90:
case 91:
case 92:
System.out.println("VERY GOOD");
break;
case 93:
case 94:
case 95:
case 96:
case 97:
case 98:
case 99:
System.out.println("EXCELLENT");
break;
default:
System.out.println("INVALID Grade");
break;
}
}
}
10.
import java.util.Scanner;
public class Prob22_Commodity_Switch_HABBILING {
int q, p;
double total;
switch(cc){
case "a":
case "A":
System.out.print("Quantity Bought: ");
q = Keyboard.readInt();
System.out.print("Unit Price: ");
p = Keyboard.readInt();
total = p*q*0.85;
System.out.printf("Total Amount: %.2f",total);
break;
case "b":
case "B":
System.out.print("Quantity Bought: ");
q = Keyboard.readInt();
System.out.print("Unit Price: ");
p = Keyboard.readInt();
total = p*q*1.10;
System.out.printf("Total Amount: %.2f",total);
break;
case "c":
case "C":
System.out.print("Quantity Bought: ");
q = Keyboard.readInt();
System.out.print("Unit Price: ");
p = Keyboard.readInt();
total = p*q;
System.out.printf("Total Amount: %.2f",total);
break;
default:
System.out.println("INVALID Code");
}
}
}