0% found this document useful (0 votes)
25 views4 pages

Java Programs for Discounts and Salaries

The document contains four Java programs. Program 1 calculates the amount to be paid for a digital camera after applying a discount and GST. Program 2 computes discounts on a laptop and printer, while Program 3 calculates gross and net pay for an employee, and Program 4 demonstrates input and output of various data types.

Uploaded by

narutofromspain
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views4 pages

Java Programs for Discounts and Salaries

The document contains four Java programs. Program 1 calculates the amount to be paid for a digital camera after applying a discount and GST. Program 2 computes discounts on a laptop and printer, while Program 3 calculates gross and net pay for an employee, and Program 4 demonstrates input and output of various data types.

Uploaded by

narutofromspain
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Program 1:

A shopkeeper offers 10% discount on the printed price of a Digital Camera.


However, a customer has to pay 6% GST on the remaining amount. Write a
program in Java to calculate the amount to be paid by the customer taking
printed price as an input.

import [Link];

public class CameraPrice


{
public static void main(String args[]) {
Scanner in = new Scanner([Link]);
[Link]("Enter printed price of Digital Camera:");
double mrp = [Link]();
double disc = mrp * 10 / 100.0;
double price = mrp - disc;
double gst = price * 6 / 100.0;
price += gst;
[Link]("Amount to be paid: " + price);
}
}

Program 2:
A computer manufacturing company announces a special offer to their
customers on purchasing laptops and the printers accordingly.

On Laptop: Discount=15%

On Printers: Discount=10%

Write a program in java to calculate the discount, when a customer


purchases a laptop and printer.

import [Link];

public class DiscountCalculator {

public static void main(String[] args) {


Scanner scanner = new Scanner([Link]);

// Get the price of the laptop from the user

[Link]("Enter the price of the laptop: $");

double laptopPrice = [Link]();

// Get the price of the printer from the user

[Link]("Enter the price of the printer: $");

double printerPrice = [Link]();

// Calculate the discount for laptop (15%)

double laptopDiscount = laptopPrice * 0.15;

// Calculate the discount for printer (10%)

double printerDiscount = printerPrice * 0.10;

// Calculate total discount

double totalDiscount = laptopDiscount + printerDiscount;

// Display the total discount

[Link]("Total discount: $" + totalDiscount);

// Calculate and display the total amount to be paid by the customer

double totalPrice = laptopPrice + printerPrice - totalDiscount;

[Link]("Total amount to be paid: $" + totalPrice);

[Link]();
}

Program 3:
import [Link].*;
public class Comp
{
public static void main(String args[])
{
Scanner in = new Scanner([Link]);
int basic;
double da,hra,pf,gp=0,np=0;
String name;
[Link]("Enter the name of the employee");
name=[Link]();
[Link]("Enter Basic Salary");
basic=[Link]();
da=basic*30.0/100.0;
hra=basic*12.5/100.0;
pf=basic*10.0/100.0;
gp=basic+da+hra;
np=gp-pf;
[Link]("Employee's Name:"+name);
[Link]("Gross pay :Rs."+gp);
[Link]("Net pay:Rs."+np);
}
}

Program 4:
import [Link].*;
public class idk
{
public static void main(String args[])
{
Scanner sc=new Scanner ([Link]);
int a;
float b;
String str;
char ch;

[Link]("Enter intege value");


a=[Link]();
[Link]("Enter float value");
b=[Link]();
[Link]("Enter string value");
str=[Link]();
[Link]("Enter charcter value");
ch=[Link]().charAt(0);

[Link]("Intege value");
[Link](a);
[Link]("Float value");
[Link](b);
[Link]("String value");
[Link](str);
[Link]("Charcter value");
[Link](ch);

Common questions

Powered by AI

Benefits of real-time discount and price calculations include enhanced accuracy in transactions, improved customer satisfaction through transparent pricing, and better inventory and financial management. Challenges may involve handling a wide variation of discounts and taxes across regions, ensuring system scalability to manage extensive data, and maintaining secure and efficient processing amid high transaction volumes .

Strategies include employing robust input validation routines, using exception handling to catch input mismatches, and ensuring type compatibility through methods such as parseInt() for strings to integers. Structuring applications to segregate input from processing logic and leveraging objects to encapsulate related data can also enhance accuracy and efficiency in handling diverse input types .

First, obtain the price of both the laptop and the printer. Calculate the discount for the laptop as 15% of its price and for the printer as 10% of its price. Sum both discount amounts to get the total discount. Subtract the total discount from the combined original prices of the laptop and printer to find the total amount that needs to be paid by the customer .

First, calculate the discount on the printed price by multiplying the printed price by 10% to obtain the discount amount, then subtract this discount from the printed price. Next, calculate the GST by applying 6% on the remaining amount after discount. Finally, add the GST to the post-discount price to get the final amount to be paid by the customer .

Considering both discounts and taxes is crucial for presenting a realistic cost to the consumer. Discounts reduce the effective sales price, making it more attractive to buyers, while taxes, such as GST, are legally required charges that contribute to government revenue but increase the final price that consumers pay. Accurate calculations ensure compliance with tax laws and transparency in pricing, fostering trust and informed purchase decisions .

Allowances like DA and HRA supplement the basic salary by accounting for cost-of-living and housing expenses, thereby increasing the gross pay. Deductions such as PF reduce the gross salary to arrive at the net pay, impacting the take-home pay directly. Therefore, they ensure statutory compliance and aid in employees' financial planning by systematically facilitating savings and supporting livelihood .

Handling multiple data types using simple user input methods such as Scanner ensures flexibility and robustness in Java applications. It requires understanding data type compatibility and conversion, such as using nextInt(), nextFloat(), next(), and next().charAt(0) to correctly parse and store different types of inputs. This practice improves program reliability and usability by efficiently handling various input scenarios .

Start by calculating the Dearness Allowance (DA) as 30% of the basic salary, and the House Rent Allowance (HRA) as 12.5% of the basic salary. The Provident Fund (PF) is calculated as 10% of the basic salary and is considered a deduction. The gross pay (GP) is the sum of the basic salary, DA, and HRA. The net pay (NP) is obtained by subtracting the PF from the GP .

The Scanner class enables easy parsing of primitive types and strings from the input stream, providing methods like nextInt(), nextFloat(), and nextLine() to get user input in command-line applications. However, limitations include the complexity of correctly managing the input buffer, handling exceptions, and distinguishing between different input types, as mis-use can lead to unintended behavior or errors .

To handle multiple data types consistently, use classes like Scanner for input and methods to convert between types as needed, employing parsing functions specifically designed for each type. This involves implementing and managing exception handling to address input mismatches and to optimize resource usage, such as closing streams when operations are complete .

You might also like