0% found this document useful (0 votes)
6 views8 pages

Program 1

The document contains seven Java programs, each demonstrating different functionalities such as checking if a number is positive, negative, or zero, finding the greatest of three numbers, determining leap years, calculating electricity bills, managing railway ticket bookings, applying discounts in an e-shop, and evaluating movie ratings. Each program includes variable definitions, user input handling, and output statements. The variable names and their data types are also provided for clarity.
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)
6 views8 pages

Program 1

The document contains seven Java programs, each demonstrating different functionalities such as checking if a number is positive, negative, or zero, finding the greatest of three numbers, determining leap years, calculating electricity bills, managing railway ticket bookings, applying discounts in an e-shop, and evaluating movie ratings. Each program includes variable definitions, user input handling, and output statements. The variable names and their data types are also provided for clarity.
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

import [Link];

public class NumberCheck {

public static void main(String[] args) {

Scanner scanner = new Scanner([Link]);

[Link]("Enter a number: ");

double number = [Link]();

if (number > 0) {

[Link]("The number is positive.");

} else if (number < 0) {

[Link]("The number is negative.");

} else {

[Link]("The number is zero.");

Variable Name Data Type Description

scanner Scanner Reads input from the user

number double Stores the number entered by user

Program 2

import [Link];

public class GreatestOfThree {

public static void main(String[] args) {

Scanner scanner = new Scanner([Link]);

[Link]("Enter first number: ");

int a = [Link]();

[Link]("Enter second number: ");

int b = [Link]();
[Link]("Enter third number: ");

int c = [Link]();

if (a >= b && a >= c) {

[Link](a + " is the greatest.");

} else if (b >= a && b >= c) {

[Link](b + " is the greatest.");

} else {

[Link](c + " is the greatest.");

Variable Name Data Type Description

scanner Scanner Reads input from the user

a int Stores the first number

b int Stores the second number

c int Stores the third number

Program 3

import [Link];

public class LeapYearCheck {

public static void main(String[] args) {

Scanner scanner = new Scanner([Link]);

[Link]("Enter a year: ");

int year = [Link]();

if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {

[Link](year + " is a leap year.");

} else {

[Link](year + " is not a leap year.");

}
}

Variable Name Data Type Description

scanner Scanner Reads input from the user

year int Stores the year entered by the user

Program4

import [Link];

public class ElectricityBill {

public static void main(String[] args) {

Scanner scanner = new Scanner([Link]);

[Link]("Enter units consumed: ");

int units = [Link]();

double bill;

if (units <= 100) {

bill = units * 1.25;

} else if (units <= 200) {

bill = 100 * 1.25 + (units - 100) * 1.50;

} else {

bill = 100 * 1.25 + 100 * 1.50 + (units - 200) * 1.80;

[Link]("Total electricity bill: ₹" + bill);

Variable Name Data Type Description

scanner Scanner Reads input from the user

units int Stores the number of electricity units used

bill double Stores the calculated electricity bill


Program 5

import [Link];

public class RailwayTicket {

String name;

String coach;

long mobno;

int amt;

int totalamt;

void accept() {

Scanner scanner = new Scanner([Link]);

[Link]("Enter customer name: ");

name = [Link]();

[Link]("Enter coach (First_AC / Second_AC / Third_AC / Sleeper): ");

coach = [Link]();

[Link]("Enter mobile number: ");

mobno = [Link]();

[Link]("Enter base ticket amount: ");

amt = [Link]();

void update() {

if ([Link]("First_AC")) {

totalamt = amt + 700;

} else if ([Link]("Second_AC")) {

totalamt = amt + 500;

} else if ([Link]("Third_AC")) {

totalamt = amt + 250;

} else if ([Link]("Sleeper")) {

totalamt = amt;
} else {

totalamt = amt;

void display() {

[Link]("Customer Name: " + name);

[Link]("Coach: " + coach);

[Link]("Mobile Number: " + mobno);

[Link]("Total Amount to Pay: ₹" + totalamt);

public static void main(String[] args) {

RailwayTicket ticket = new RailwayTicket();

[Link]();

[Link]();

[Link]();

Variable Name Data Type Description

name String Stores the name of the customer

coach String Stores the type of coach selected

mobno long Stores the customer's mobile number

amt int Stores the base amount of the ticket

totalamt int Stores the final amount to be paid after adjustment

scanner Scanner Used to read input from the user

Program 6

import [Link];

public class Eshop {


String name;

double price;

double netAmount;

void accept() {

Scanner scanner = new Scanner([Link]);

[Link]("Enter item name: ");

name = [Link]();

[Link]("Enter item price: ");

price = [Link]();

void calculate() {

if (price >= 1000 && price <= 25000) {

netAmount = price - (price * 0.05);

} else if (price <= 57000) {

netAmount = price - (price * 0.075);

} else if (price <= 100000) {

netAmount = price - (price * 0.10);

} else {

netAmount = price - (price * 0.15);

void display() {

[Link]("Item Name: " + name);

[Link]("Net Amount to Pay: ₹" + netAmount);

public static void main(String[] args) {

Eshop item = new Eshop();


[Link]();

[Link]();

[Link]();

Variable Name Data Type Description

name String Stores the name of the item

price double Stores the original price of the item

netAmount double Stores the price after applying discount

scanner Scanner Used to read user input

Program 7

import [Link];

public class movieMagic {

int year;

String title;

float rating;

movieMagic() {

year = 0;

title = "";

rating = 0.0f;

void accept() {

Scanner scanner = new Scanner([Link]);

[Link]("Enter year of release: ");

year = [Link]();

[Link](); // consume the leftover newline

[Link]("Enter movie title: ");


title = [Link]();

[Link]("Enter movie rating (0.0 to 5.0): ");

rating = [Link]();

if (rating >= 0.0 && rating <= 2.0) {

[Link]("Rating: Flop");

public static void main(String[] args) {

movieMagic movie = new movieMagic();

[Link]();

Variable Name Data Type Description

year int Stores the year the movie was released

title String Stores the title of the movie

rating float Stores the popularity rating (0.0 to 5.0)

scanner Scanner Used to read input from the user

You might also like