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

Q1-Write a program to input employee name (String) and the

salary (double). Then compute the tax which equal 5% from


salary if the salary is less than or equal 500 otherwise the tax
equal 10% from the salary , and compute the net salary which
equal salary –Tax.
Input output

Ahmed 570.700 Name: Ahmed

Salary =570.700

Tax = 28.535

Nat salary =542.165

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

Scanner keyboard =new Scanner (System. in);


String name;
double sal,tax,nsal;
System.out.println(" enter employee name");
name=keyboard.nextLine();
System.out.println(" enter employee salary");
sal=keyboard.nextDouble();
if(sal <=500 ) tax=0.05*sal ;
else tax=0.1*sal;
nsal=sal-tax;
System.out.println("Employee name :"+name);
System.out.println("Employee salary ",sal);
System.out.printmln("Employee tax : "+tax);
System.out.println("Employee net salary : "+nsal);
}
}
Q2:-Write a program that asks the user to input the “air” ,”water” ,or “steel” in any case,
and the distance in feet that a sound wave will travel in medium. Any other medium print
in valid message and quit the program. Your program is required to display the amount
of time it will take using the speed specified in table below. Note the

Time =distance÷ speed.

Medium speed
Air 1,100 feet per seconds
Water 4,900 feet per seconds
Steel 16,400 feet per seconds

Sample input/output

Enter a medium and distance


Water 6304.6
The time to travel water is 1.28665 feet

Solution
import java.util.Scanner;
public class q2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double time=0;
String name;
double distance;
System.out.println("Enter medium and distanc");
name = input. Next();
distance = input.nextDouble();
if (name.equalsIgnoreCase("air"))
time = distance / 1100;
else if (name.equalsIgnoreCase("water"))

time = distance / 4900;


else if (name.equalsIgnoreCase("steel"))

time = distance / 16400;


else {
System.out.println("invalid medium");
System.exit(0);
}
System.out.println("the time to travel in " + name + "is" + time +
"seconds");

}
}
Q3:- write a program that asks a user to enter a temperature .The program then
prints a message describing the weather according to the following table :-

Temperature Message
T <10 COLD
10≤T<20 PLEASANT
20≤T<30 WARM
T≥30 HOT

Q4:- write a program that asks user to input a digit from 2 to 9.your program print corresponding letters
on mobile phone keyboard as shown in the table below:-

digit 2 3 4 5 6 7 8 9
Letters ABC DEF GHI MNO PQRS TUV WXYZ TEV

Display an invalid message in case the user enters an invalid digit;

Sample run 1 sample run 2 sample run 3

Enter a digit 4 Enter a digit 7 Enter a digit 12

GHI TUV Invalid digit

Q5_ Write program to calculate and output the net price of a pizza based on one

user input:

1- The number of pizza;

   2- Size (S for small, M for medium, or L for large). The net price of pizza is the sum of the
follows:

    2- Base price of the pizza is $8.50 for small, $10.50 for medium, and $12.50 for large. any
other type is $20.00

    • Sales tax is an additional 7% of the total price.


Solution
import java.util.Scanner;
public class q2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int no;
char type;
double b=0,tax,tp,total;
System.out.println("Enter the pizza number and type");
no=input.nextInt();
type=input.next().charAt(0);
if(type=='S' || type=='s')b=8.5;
else
if(type=='M' || type=='m')b=10.5;
else
if(type=='L' || type=='l')b=12.5;
tp=no*b;
tax=.07*tp;
total=tp+tax;
System.out.println("the total price you have to pay="+total);
}
}

Q6:-A whole sale department is offering reduced price on large orders of kitchen utensils. Write
program to calculate and display the net price of an order based on three user inputs:
price(float) ,quantity (int) and payment method char :A for each in advanced, D for cash on
delivery). The net price of the order is calculated as follows: -

Net price=(price – discount1- discount2 ) x Quantity.

Discount1= 4% of price for quantities more than or equal to 1000 otherwise 2% of price.

Discount2=5% of price for cash in advance payment and no discount for cash on delivery.

Sample input/output

Enter price, quantity and payment method (A or D)

10 2500 A

The price is 22750


Solution

import java.util.Scanner;

public class q2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int q;
double price, netprice, d1, d2;
char pa;
System.out.println("enter price and quantity and paymen");
price = input.nextDouble();
q = input.nextInt();
pa = input.next().charAt(0);

if (q >= 1000) d1 = .04 * price;


else
d1 = .02 * price;
if (pa == 'A') d2 = .05 * price;
else
d2 = 0;
netprice = (price - d1 - d2) * q;
System.out.println("the toala price =" + netprice);

}
}
Q7: -mobile wallet is virtual wallet that stores payment card information on
mobile device. Write a program that asks user to enter three numbers: wallet
balance, mobile number. to pay money to (assume mobile number is exactly 8
digits). And the amount of money to pay and performs the following:

1- Calculate the discount amount on the amount of money to pay according to


the following table –

when to get discount ? Discount


If mobile number start with 44 Discount=5%from money to pay
If mobile number start with 88 Discount=7%from money to pay
Other numbers Discount=0%

2- Calculate: price =money to pay –discount.


3- Display the error message “Transaction failed “if the price is larger the wallet
balance. otherwise display the price and new wallet balance (subtract from
wallet balance the price).

Sample input/output Sample 2 input/output

200 44111133 100 80 44555500 100

Price=85 Price=100

New balance: 105 Transaction failed

Conditional operator
WHAT IS THE OUPUTOF THE FOLOWING C++ CODE:-

int a=-4,j; 16

j=(a>=0?0:a*a)
System.out.println<(j};
WHAT IS THE OUPUTOF THE FOLOWING C++ CODE:-

int x=10 ,y=20; 10


if(x>=0 || y>=30) Sytem.out.prinln(y);

else

Sytem.out.prinln(x);

You might also like