NCP2210 MP2
NCP2210 MP2
MACHINE PROBLEM #2
DECISION STRUCTURES
NAME: CRUZ, JOSH CLARENCE F. DR. JOAN P. LAZARO
SECTION: BSME 2 DATE: 3/27/22 GRADE:
Problem #1:
Write a program that prompts the user to enter a number within the range of 1 through
100. The program should display the Roman numeral version of that number. If the number is
outside the range of 1 through 100, the program should display an error message.
if (num == 100)
system.print(“C”);
else if ((num > 100) || (num <1))
system.print(“ERROR”);
else {
(int) tens = num / 10 //Ex. 79 / 10 = 7
(int) ones = num % 10 // Ex. 79 % 10 = 9
switch (tens) {
case 9: system.print(“XC”); break;
case 8: system.print(“LXXX”); break;
……
default: system.print(“ “); }
switch (ones) {
case 9: system.print(“IX”); break;
case 8: system.print(“VIII”); break;
….
case 1: system.print(“I”); break;
default: sytem.print (“ “); }
1|Page
NCP 3106 (Software Design Laboratory)
Program 1:
package mp2;
import java.util.Scanner;
/**
*
* @author Josh Cruz
*/
public class Prob1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
int number;
int tens = 0;
int ones = 0;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a Number: ");
number = keyboard.nextInt();
if (number == 100) {
System.out.println("C");
}
else if ((number > 100) || (number <1)) {
System.out.println("ERROR");
}
else {
tens = number/10;
ones = number%10;
}
{
System.out.print("Equivalent in Roman Numeral:" );
}
{
switch (tens) {
case 1: System.out.print("Equivalent in Roman Numeral:X"); break;
case 2: System.out.print("Equivalent in Roman Numeral:XX"); break;
case 3: System.out.print("Equivalent in Roman Numeral:XXX"); break;
case 4: System.out.print("Equivalent in Roman Numeral:XL"); break;
case 5: System.out.print("Equivalent in Roman Numeral:L"); break;
case 6: System.out.print("Equivalent in Roman Numeral:LX"); break;
case 7: System.out.print("Equivalent in Roman Numeral:LXX"); break;
case 8: System.out.print("Equivalent in Roman Numeral:LXXX"); break;
case 9: System.out.print("Equivalent in Roman Numeral:XC"); break;
default: System.out.print(" "); }
2|Page
NCP 3106 (Software Design Laboratory)
switch (ones) {
case 1: System.out.println("I"); break;
case 2: System.out.println("II"); break;
case 3: System.out.println("III"); break;
case 4: System.out.println("IV"); break;
case 5: System.out.println("V"); break;
case 6: System.out.println("VI"); break;
case 7: System.out.println("VII"); break;
case 8: System.out.println("VIII"); break;
case 9: System.out.println("IX"); break;
OUTPUT 1:
OUTPUT 2:
OUTPUT 3:
3|Page
NCP 3106 (Software Design Laboratory)
4|Page
NCP 3106 (Software Design Laboratory)
Problem #2:
Write a program that calculates and displays a person’s body mass index (BMI). 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 is calculated with the following formula:
BMI = Weight * 703 / Height2
where weight is measured in pounds and height is measured in inches. The program should
display a message indicating whether the person has optimal weight, is underweight, or is
overweight. A sedentary person’s weight is considered optimal if his or her BMI is between 18.5
and 25. If the BMI is less than 18.5, the person is considered underweight. If the BMI value is
greater than 25, the person is considered overweight.
Program 2:
package mp2;
import java.util.Scanner;
/**
*
* @author Josh Cruz
*/
public class Prob2
{
public static void main(String[] args)
{
double weight;
double height;
double BMI;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter your weight in pounds: ");
weight = keyboard.nextDouble();
5|Page
NCP 3106 (Software Design Laboratory)
OUTPUT 1:
OUTPUT 2:
OUTPUT 3:
6|Page
NCP 3106 (Software Design Laboratory)
7|Page
NCP 3106 (Software Design Laboratory)
Problem #3:
Write a program that has variables to hold three test scores. The program should ask the
user to enter three test scores and then assign the values entered to the variables. The program
should display the average of the test scores and the letter grade that is assigned for the test score
average. Use the grading scheme in the following table:
Test Score Average Letter Grade Test Score Average Letter Grade
93-100 A 73-76 C
90-92 A- 70-72 C-
87-89 B+ 67-69 D+
83-86 B 63-66 D
80-82 B- 60-62 D-
77-79 C+ Below 60 F
Program 3:
package mp2;
import java.util.Scanner;
/**
*
* @author Josh Cruz
*/
public class Prob3
{
public static void main(String[] args)
{
double score1;
double score2;
double score3;
double average;
if (average<60)
System.out.println("Your Average score is Equivalent to F");
else if (average < 63)
8|Page
NCP 3106 (Software Design Laboratory)
else if (average<67)
System.out.println("Your Average score is Equivalent to D");
else if (average<70)
System.out.println("Your Average score is Equivalent to D+");
else if (average<73)
System.out.println("Your Average score is Equivalent to C-");
else if (average< 7)
System.out.println("Your Average score is Equivalent to C");
else if (average<80)
System.out.println("Your Average score is Equivalent to C+");
else if (average<83)
System.out.println("Your Average score is Equivalent to B-");
else if (average<87)
System.out.println("Your Average score is Equivalent to B");
else if (average<90)
System.out.println("Your Average score is Equivalent to B+");
else if (average<93)
System.out.println("Your Average score is Equivalent to A-");
else if (average < 101)
System.out.println("Your Average score is Equivalent to A");
}
}
OUTPUT 1:
OUTPUT 2:
OUTPUT 3:
9|Page
NCP 3106 (Software Design Laboratory)
3.
10 | P a g e
NCP 3106 (Software Design Laboratory)
Problem #4:
A software company sells a package that retails for P888. Quantity discounts are given according
to the following table:
Quantity Discount
10–19 20%
20–49 30%
50–99 40%
100 or more 50%
Write a program that asks the user to enter the number of packages purchased. The
program should then display the amount of the discount (if any) and the total amount of the
purchase after the discount.
Program 4:
package mp2;
import java.util.Scanner;
/**
*
* @author Josh Cruz
*/
public class Prob4
{
public static void main(String[] args)
{
double packs;
double price;
double discount;
double amount;
11 | P a g e
NCP 3106 (Software Design Laboratory)
amount = (packs*888)-(packs*888)*0.4;
System.out.println("You have a 40% discount! You have saved Php" + discount);
System.out.println("The discounted anount is Php" + amount); }
else {
discount = (packs*888)*0.5;
amount = (packs*888)-(packs*888)*0.5;
System.out.println("You have a 50% discount! You have saved Php" + discount);
System.out.println("The discounted anount is Php" + amount); }
}
}
OUTPUT 1:
OUTPUT 2:
OUTPUT 3:
12 | P a g e
NCP 3106 (Software Design Laboratory)
4.
Problem #5:
The Lost Boxes Company charges the following rates:
Weight of Package Rate per 500 meters Shipped
Not more than 1 kilogram P139.99
Not more than 3 kilograms P359.99
Not more than 5 kilograms P579.99
Not more than 10 kilograms P799.99
Not more than 20 kilograms P1319.99
The shipping charges per 500 meters are not prorated. For example, if a 1-kilogram
package is shipped 550 meters, the charges would be P279.98. Write a program that asks the user
to enter the weight of a package in kilograms, the distance to be the package will be shipped and
then displays the shipping charges.
13 | P a g e
NCP 3106 (Software Design Laboratory)
Program 5:
package mp2;
import java.util.Scanner;
/**
*
* @author Josh Cruz
*/
public class Prob5
{
public static void main(String[] args){
double weight;
int distance;
int distanceR,distanceL;
double amount1,amount2,amount3,amount4,amount5;
14 | P a g e
NCP 3106 (Software Design Laboratory)
}
}
}
OUTPUT 1:
OUTPUT 2:
OUTPUT 3:
15 | P a g e
NCP 3106 (Software Design Laboratory)
5.
16 | P a g e