1. LAB 3
NUR IZZATUL BINTISAFINGAI(178969)
//Question 1
//NUR IZZATUL BINTI SAFINGAI(178969)
// BACELOR SAINS KOMPUTER PENGKHUSUSAN SISTEM KOMPUTER
// LAB 3
import java.util.Scanner;
public class PriceDiscount {
public static void main(String[] args) {
//declare variable
int numberItem;
double Price, afterDiscount;
//Create scanner and user input the data
Scanner p= new Scanner(System.in) ;
System.out.print("Enter number of item brought: ");
numberItem=p.nextInt();
System.out.print("Enter price of item: RM ");
Price=p.nextDouble();
//condition, the calculation of price after discount
//display the result
if ((numberItem >=1) && (numberItem <=9))
if ((Price >= 0.01) && (Price<= 10.0))
{
afterDiscount=(Price-(0 * Price))*(numberItem);
System.out.println("The total price is RM "+afterDiscount);
}
else if ((Price >= 10.01) && (Price<= 100.00))
{
afterDiscount=(Price-(0.02 * Price))*(numberItem);
System.out.println("The total price is RM "+ afterDiscount);
}
else if (Price== 100.01)
{
afterDiscount=(Price-(0.05 * Price))*(numberItem);
System.out.println("The total price is RM"+afterDiscount);
}
if((numberItem >=10) && (numberItem <=99))
if ((Price >= 0.01) && (Price<= 10.0))
{
afterDiscount=(Price-((0.05) * Price))*(numberItem);
System.out.println("The total price is RM "+afterDiscount);
}
2. else if((Price >= 10.01) && (Price<= 100.00))
{
afterDiscount=(Price-(0.07 * Price))*(numberItem);
System.out.println("The total price is RM "+afterDiscount);
}
else if (Price ==100.01)
{
afterDiscount=(Price-(0.09 * Price))*(numberItem);
System.out.println("The total price is RM "+afterDiscount);
}
if((numberItem >=100) && (numberItem <=499))
if ((Price >= 0.01) && (Price<= 10.0))
{
afterDiscount=(Price-(0.09 * Price))*(numberItem);
System.out.println("The total price is RM "+afterDiscount);
}
else if((Price >= 10.01) && (Price<= 100.00))
{
afterDiscount=(Price-(0.15 * Price))*(numberItem);
System.out.println("The total price is RM "+afterDiscount);
}
else if (Price ==100.01){
afterDiscount=(Price-(0.21 * Price))*(numberItem);
System.out.println("The total price is RM "+afterDiscount);
}
if((numberItem >=500) && (numberItem <=999))
if ((Price >= 0.01) && (Price<= 10.0))
{
afterDiscount=(Price-(0.14 * Price))*(numberItem);
System.out.println("The total price is RM "+afterDiscount);
}
else if((Price >= 10.01) && (Price<= 100.00))
{
afterDiscount=(Price-(0.23 * Price))*(numberItem);
System.out.println("The total price is RM "+afterDiscount);
}
else if (Price ==100.01)
{
afterDiscount=(Price-(0.32 * Price))*(numberItem);
System.out.println("The total price is RM "+afterDiscount);
}
if(numberItem >=1000)
if ((Price >= 0.01) && (Price<= 10.0))
{
afterDiscount=(Price-(0.21 * Price))*(numberItem);
3. System.out.println("The total price is RM "+afterDiscount);
}
else if((Price >= 10.01) && (Price<= 100.00))
{
afterDiscount=(Price-(0.32 * Price))*(numberItem);
System.out.println("The total price is RM "+afterDiscount);
}
else if (Price ==100.01)
{
afterDiscount=(Price-(0.43 * Price))*(numberItem);
System.out.println("The total price is RM "+afterDiscount);
}
}
}
//Question 2
//NUR IZZATUL BINTI SAFINGAI(178969)
// BACELOR SAINS KOMPUTER PENGKHUSUSAN SISTEM KOMPUTER
// LAB 3
import java.util.Scanner;
public class VendingMachine {
public static void main(String[] args) {
//create scanner
Scanner p= new Scanner(System.in) ;
double p1 = 1.25;
double p2 = 0.75;
double p3 = 0.90;
double p4 = 0.75;
double p5 = 1.50;
double p6 = 0.75;
//Display the list of item with the price
System.out.println("List of item");
System.out.println("");
System.out.println("Item 1: "+p1);
System.out.println("Item 2: "+p2);
System.out.println("Item 3: "+p3);
System.out.println("Item 4: "+p4);
System.out.println("Item 5: "+p5);
System.out.println("Item 6: "+p6);
System.out.print("n");
//User enter data
System.out.print("Enter an item number: ");
int item_number= p.nextInt();
System.out.print("Enter the price: RM ");
double price= p.nextDouble();
System.out.print("Enter sum of money: RM ");
double sumMoney= p.nextDouble();
4. System.out.print("n");
//compute formula
double change=sumMoney-price;
double notEnough=price-sumMoney;
//Display the result based on user's input
if ((price ==sumMoney)||(sumMoney>price))
{
System.out.println("Enter an item number and sum of money:
"+item_number+" "+sumMoney);
System.out.println("Thank you for buying item "+item_number+".
Your change is RM "+change);
}
else
{
System.out.println("Enter an item number and sum of money:
"+item_number+" "+sumMoney);
System.out.print("Please insert another RM "+notEnough);
}
}
}
//Question 3
//NUR IZZATUL BINTI SAFINGAI(178969)
// BACELOR SAINS KOMPUTER PENGKHUSUSAN SISTEM KOMPUTER
// LAB 3
public class Menu {
public static void main(String[] args) {
double price= 4.99;
double price1= 2.00;
double price2= 1.00;
//Display the menu
System.out.println("1. Cheeseburger RM "+price);
System.out.println("2. Pepsi RM "+price1);
System.out.println("3. Fun Fries RM " +price2);
}
}
5. //Question 4
//NUR IZZATUL BINTI SAFINGAI(178969)
// BACELOR SAINS KOMPUTER PENGKHUSUSAN SISTEM KOMPUTER
// LAB 3
import java.util.Scanner;
public class WeeklyEmployee {
public static void main(String[] args) {
double net_pay;
String name;//Declare variable
Scanner input=new Scanner(System.in);
System.out.print("Employee name: ");
name=input.next();
int hours_work;//Declare variable
Scanner input1=new Scanner(System.in);
System.out.print("Hours per week: ");
hours_work=input1.nextInt();
int wage_rate;//declare variable
Scanner input2=new Scanner(System.in);
System.out.print("Hourly wage rate: ");
wage_rate=input2.nextInt();
System.out.println("n");
if (hours_work <= 40)
{
//compute formula
double gross_pay= hours_work*wage_rate;
net_pay=gross_pay-((3.625/100)*gross_pay);
//Display the result
System.out.println("Employee: "+name);
System.out.println("Gross pay: "+gross_pay);
System.out.println("Net pay: "+net_pay);
}
else if (hours_work> 40)
{
//compute formula
double over_hours=((hours_work-40)*wage_rate);
double gross_pay=(0.5*over_hours)+over_hours+40;
net_pay=gross_pay-((3.625/100)*gross_pay);
//Display the result
System.out.println("Employee: "+name);
System.out.println("Gross pay: "+gross_pay);
System.out.println("Net pay: "+net_pay);
}
}
}