NAME : MOHD AZMAL SHAHFARI BIN KAMARUL ZAMA
ID : 21BT02014
Write a JAVA code to calculate
and display the net salary. Net salary is calculated by subtracting (15%) from
gross salary.
(10 marks)
1.
import java.util.Scanner;
public class LabTest1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner io=new Scanner (System.in);
//Variables
Double netsalary, gross_salary;
//Input
System.out.println("Please enter your gross salary.");
gross_salary=io.nextDouble();
//Process
netsalary=85*gross_salary/100;
//Output
System.out.println("You net salary is " + netsalary + ("."));
}
A car park has the following charges. The
1st hour costs RM2.00. The subsequent hours cost RM1.00 per hour. Calculate
and display the car park charge.
(10 marks)
2.
import java.util.Scanner;
public class LabTest2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner io=new Scanner (system.in);
//Variables
int entrytime,exittime,charge, period;
//Input
System.out.println("Please enter your entry time.");
entrytime=io.nextInt();
System.out.println("Please enter your exit time.");
exittime=io.nextInt();
//Process
period = exittime -entrytime;
if (period<=1)
charge=2;
else
charge=2+(period-1);
//output
System.out.println("Your total car park charge is " + charge + ".");
Using decision logic structure, write a program for the following
problem:
A program allows the user to enter any two integer’s values and another single digit called code.
Depending on what the user input for the code, do the following:
If the code is 1, 2 or 3, display the sum of the two integers.
If the code is 4, 7 or 8, display the multiplication of the two integers
If the code is 5 or 6, display the division of first integer with the second integer.
Remember to check division by zero. Any other values of code, display the invalid message.
(20 marks)
3.
import java.util.Scanner;
public class LabTest3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner io=new Scanner (System.in);
float integer1, integer2, code;
float finalanswer;
System.out.println("Please enter the first integer.");
integer1=io.nextInt();
System.out.println("Please enter the second integer.");
integer2=io.nextInt();
System.out.println("Please enter the code.");
code=io.nextInt();
finalanswer=integer1;
if ( code > 0 && code < 4) {
finalanswer = integer1 + integer2;
System.out.println(finalanswer);
else if(code==4 || code==7 || code==8) {
finalanswer = integer1*integer2;
System.out.println(finalanswer);
}
else if (code==5 || code==6) {
if(integer2 == 0) {
System.out.println(
"Error, Divided by zero operation is not possible");
else {
finalanswer=integer1/integer2;
System.out.println(finalanswer);
} else {
System.out.println("Invalid code.");}