NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

programme 1

import java.util.Scanner;



public class Table {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Name: Manish SinghnUID: 21BCS5294n");

int[] empIds = {1001, 1002, 1003, 1004, 1005, 10006, 1007};

String[] empNames = {"Manish", "Harshit", "Abhay", "David", "Raj", "Hardik", "Rohit"};

String[] date = {"01/04/2009", "23/08/2012", "12/11/2008", "29/01/2013", "16/07/2005",

"01/01/2000", "12/06/2006"};

String[] designations = {"e", "c", "k", "r", "m", "e", "c"};

String[] dept = {"R & D", "PM", "Acct", "Front Desk", "Engg", "Manufacturar", "PM"};

int[] Basic = {20000, 30000, 10000, 12000, 50000, 23000, 29000};

int[] HRA = {8000, 12000, 8000, 6000, 20000, 9000, 12000};

int[] IT = {3000, 9000, 1000, 2000, 20000, 4400, 10000};

System.out.print("Enter Employee ID: ");

int find = sc.nextInt();

int index = -1;

for (int i = 0; i < empIds.length; i++) {

if (empIds[i] == find) {

index = i;

break;

}

}

if (index != -1) {

int salary = Basic[index] + HRA[index] - IT[index];

switch (designations[index]) {

case "e":

salary += 20000;

designations[index] = "Engineer";

break;

case "c":

salary += 32000;

designations[index] = "Consultant";

break;

case "k":

salary += 12000;

designations[index] = "Clerk";

break;

case "r":

salary += 15000;

designations[index] = "Receptionist";

break;

case "m":

salary += 40000;

designations[index] = "Manager";

break;

default:

break;

}

System.out.println("Emp No. | Emp Name | Department | Designation | Salary");

System.out.println(empIds[index] + " " + empNames[index] + " " + dept[index] + " " + designations[index] +

" " + salary);

} else {

System.out.println("Employee ID not found!");

}

}

}

Programe 2

import java.util.*;



class Video {

private String title;

private boolean checkedOut;

private int rating;



public Video(String title) {

this.title = title;

checkedOut = false;

rating = 0;

}



public String getTitle() {

return title;

}



public boolean isCheckedOut() {

return checkedOut;

}



public void setCheckedOut(boolean checkedOut) {

this.checkedOut = checkedOut;

}



public int getRating() {

return rating;

}



public void addRating(int rating) {

this.rating += rating;

}

}



class VideoStore {

private ArrayList<Video> inventory;



public VideoStore() {

inventory = new ArrayList<>();

}



public void addVideo(String title) {

inventory.add(new Video(title));

System.out.println("Video added successfully: " + title);

}



public void checkOutVideo(String title) {

for (Video video : inventory) {

if (video.getTitle().equalsIgnoreCase(title) && !video.isCheckedOut()) {

video.setCheckedOut(true);

System.out.println("Video checked out successfully: " + title);

return;

}

}

System.out.println("Video not available or already checked out: " + title);

}



public void returnVideo(String title) {

for (Video video : inventory) {

if (video.getTitle().equalsIgnoreCase(title) && video.isCheckedOut()) {

video.setCheckedOut(false);

System.out.println("Video returned successfully: " + title);

return;

}

}

System.out.println("Video not found or not checked out: " + title);

}



public void receiveRating(String title, int rating) {

for (Video video : inventory) {

if (video.getTitle().equalsIgnoreCase(title)) {

video.addRating(rating);

System.out.println("Rating added successfully for " + title + ": " + rating);

return;

}

}

System.out.println("Video not found: " + title);

}



public void listInventory() {

System.out.println("Video Inventory:");

for (Video video : inventory) {

System.out.println("Title: " + video.getTitle() + " | Checked Out: " + video.isCheckedOut() +

" | Rating: " + (video.getRating() == 0 ? "N/A" : video.getRating()));

}

}

}



public class Item {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

VideoStore videoStore = new VideoStore();

int choice;

do {

System.out.println("nMenu:");

System.out.println("1. Add Videos");

System.out.println("2. Check Out Videos");

System.out.println("3. Return Videos");

System.out.println("4. Receive Rating");

System.out.println("5. List Inventory");

System.out.println("6. Exit");

System.out.print("Enter your choice: ");

choice = scanner.nextInt();

scanner.nextLine(); // consume newline

switch (choice) {

case 1:

System.out.print("Enter video title to add: ");

String addTitle = scanner.nextLine();

videoStore.addVideo(addTitle);

break;

case 2:

System.out.print("Enter video title to check out: ");

String checkoutTitle = scanner.nextLine();

videoStore.checkOutVideo(checkoutTitle);

break;

case 3:

System.out.print("Enter video title to return: ");

String returnTitle = scanner.nextLine();

videoStore.returnVideo(returnTitle);

break;

case 4:

System.out.print("Enter video title to receive rating: ");

String ratingTitle = scanner.nextLine();

System.out.print("Enter rating out of 10: ");

int rating = scanner.nextInt();

if (rating <= 10 && rating >= 0) {

videoStore.receiveRating(ratingTitle, rating);

} else {

System.out.println("The Rating is incorrect..");

}

break;

case 5:

videoStore.listInventory();

break;

case 6:

System.out.println("Exiting...");

break;

default:

System.out.println("Invalid choice. Please enter a number between 1 and 6.");

}

} while (choice != 6);

scanner.close();

}

}

Programe 3



import java.util.Scanner;



class InvalidAgeException extends Exception {}

class InvalidAmountException extends Exception {}

class InvalidDaysException extends Exception {}

class InvalidMonthsException extends Exception {}



abstract class Account {

double interestRate;

double amount;

abstract double calculateInterest(double amount) throws InvalidMonthsException, InvalidAgeException, InvalidAmountException, InvalidDaysException;

}



class FDaccount extends Account {

double FDinterestRate;

double FDAmount;

int noOfDays;

int ageOfACHolder;

double General, SCitizen;

Scanner FDScanner = new Scanner(System.in);



double calculateInterest(double amount) throws InvalidAgeException, InvalidAmountException, InvalidDaysException {

this.FDAmount = amount;

System.out.println("Enter FD days");

noOfDays = FDScanner.nextInt();

System.out.println("Enter FD age holder ");

ageOfACHolder = FDScanner.nextInt();



if (amount < 0) {

throw new InvalidAmountException();

}

if (noOfDays < 0) {

throw new InvalidDaysException();

}

if (ageOfACHolder < 0) {

throw new InvalidAgeException();

}



// Rest of the code...

return FDAmount * FDinterestRate;

}

}



class RDaccount extends Account {

// Similar to FDaccount...

}



class SBaccount extends Account {

// Similar to FDaccount...

}



public class InterestCalculator {

public static void main(String[] args) {

boolean val = true;

Scanner sc = new Scanner(System.in);

System.out.println("Name: Manish SinghnUID: 21BCS5294");



while (val) {

System.out.println("SELECT THE OPTIONS " + "n1." + " Interest Calculator- SB" + " n2." + " Interest Calculator-FD" + "n3." + " Interest Calculator-RD" + "n4." + " Exit");

System.out.print("Enter your choice : ");

int choice = sc.nextInt();

switch (choice) {

case 1:

// SBaccount calculation...

break;

case 2:

// FDaccount calculation...

break;

case 3:

// RDaccount calculation...

break;

case 4:

val = false;

System.out.println("Exiting the program.");

break;

default:

System.out.println("Wrong choice");

break;

}

}

sc.close(); // Close the scanner

}

}



programe 4



import java.util.*;



class Card {

String symbol;

int number;



public Card(String symbol, int number) {

this.symbol = symbol;

this.number = number;

}



public String getSymbol() {

return symbol;

}



public int getNumber() {

return number;

}



@Override

public String toString() {

return symbol + " " + number;

}

}



public class Cards {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.println("Name: Manish SinghnUID: 21BCS5294");

System.out.print("Enter Number of Cards:");

int n = scanner.nextInt();

scanner.nextLine();



if (n <= 0) {

System.out.println("Invalid input for the number of cards.");

return;

}



Map<String, List<Card>> mp = new TreeMap<>();



for (int i = 1; i <= n; i++) {

System.out.println("Enter card " + i + ":");

String symbol = scanner.nextLine();

int number = scanner.nextInt();

scanner.nextLine();

Card card = new Card(symbol, number);

mp.computeIfAbsent(symbol, k -> new ArrayList<>()).add(card);

}



System.out.println("Distinct Symbols are:");

for (String symbol : mp.keySet()) {

System.out.print(symbol + " ");

}

System.out.println();



for (Map.Entry<String, List<Card>> entry : mp.entrySet()) {

System.out.println("Cards in " + entry.getKey() + " Symbol");

int sum = 0;

for (Card card : entry.getValue()) {

System.out.println(card);

sum += card.getNumber();

}

System.out.println("Number of cards: " + entry.getValue().size());

System.out.println("Sum of Numbers: " + sum);

}



scanner.close(); // Closing the scanner

}

}



Programme 5



import java.util.*;



class Card {

private String symbol;

private int number;



public Card(String symbol, int number) {

this.symbol = symbol;

this.number = number;

}



public String getSymbol() {

return symbol;

}



@Override

public String toString() {

return symbol + " " + number;

}



@Override

public boolean equals(Object o) {

if (this == o) return true;

if (!(o instanceof Card)) return false;

Card card = (Card) o;

return number == card.number &&

Objects.equals(symbol, card.symbol);

}



@Override

public int hashCode() {

return Objects.hash(symbol, number);

}

}



public class cards2 {

public static void main(String[] args) {

TreeSet<Card> cards = new TreeSet<>(Comparator.comparing(Card::getSymbol));

Scanner scanner = new Scanner(System.in);

System.out.println("Name: Manish SinghnUID: 21BCS5294");

System.out.print("Enter a number of cards: ");

int n = scanner.nextInt();

int i = n;

for (int j = 0; j < n; j++) {

System.out.print("Enter a card symbol: ");

String symbol = scanner.next();

System.out.print("Enter a card number: ");

int number = scanner.nextInt();

if (cards.size() < 4) {

Card card = new Card(symbol, number);

if (!cards.stream().anyMatch(c -> c.getSymbol().equals(symbol))) {

cards.add(card);

} else {

System.out.println("Symbol already exists, try another.");

j--; // Decrement j to re-prompt for the same index

}

}

}

System.out.println("Four symbols gathered in " + i + " cards.");

System.out.println("Cards in Set are :");

for (Card card : cards) {

System.out.println(card);

}

}

}



programme6

import java.util.ArrayList;

import java.util.Scanner;



public class stringlist {

public static void main(String[] args) {

ArrayList<String> itemList = new ArrayList<>();

Scanner scanner = new Scanner(System.in);

int choice;

do {

System.out.println("1. Insert");

System.out.println("2. Search");

System.out.println("3. Delete");

System.out.println("4. Display");

System.out.println("5. Exit");

System.out.print("Enter your choice: ");

choice = scanner.nextInt();

scanner.nextLine(); // Consume newline

switch (choice) {

case 1:

System.out.print("Enter the item to be inserted: ");

String item = scanner.nextLine();

itemList.add(item);

System.out.println("Inserted successfully");

break;

case 2:

System.out.print("Enter the item to search: ");

String searchItem = scanner.nextLine();

if (itemList.contains(searchItem)) {

System.out.println("Item found in the list.");

} else {

System.out.println("Item not found in the list.");

}

break;

case 3:

System.out.print("Enter the item to delete: ");

String deleteItem = scanner.nextLine();

if (itemList.remove(deleteItem)) {

System.out.println("Deleted successfully");

} else {

System.out.println("Item does not exist.");

}

break;

case 4:

System.out.println("The Items in the list are:");

for (String itemInList : itemList) {

System.out.print(itemInList + " ");

}

System.out.println();

break;

case 5:

System.out.println("Exiting...");

break;

default:

System.out.println("Invalid choice. Please enter a valid option.");

}

} while (choice != 5);

scanner.close();

}

}



programme 7



import java.io.*;

import java.util.*;



class Employee {

private int id;

private String name;

private int age;

private double salary;



public Employee(int id, String name, int age, double salary) {

this.id = id;

this.name = name;

this.age = age;

this.salary = salary;

}



public String toString() {

return id + " " + name + " " + age + " " + salary;

}

}



public class filedata {

private static final String FILE_NAME = "file.txt";

private static List<Employee> employees = new ArrayList<>();



public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

int choice;

do {

System.out.println("Main Menu");

System.out.println("1. Add an Employee");

System.out.println("2. Display All");

System.out.println("3. Exit");

System.out.print("Enter your choice: ");

choice = scanner.nextInt();

scanner.nextLine();

switch (choice) {

case 1:

addEmployee(scanner);

break;

case 2:

displayAllEmployees();

break;

case 3:

System.out.println("Exiting the System");

break;

default:

System.out.println("Invalid choice. Please enter a number between 1 and 3.");

}

} while (choice != 3);

scanner.close();

}



private static void addEmployee(Scanner scanner) {

System.out.print("Enter Employee ID: ");

int id = scanner.nextInt();

scanner.nextLine();

System.out.print("Enter Employee Name: ");

String name = scanner.nextLine();

System.out.print("Enter Employee Age: ");

int age = scanner.nextInt();

scanner.nextLine();

System.out.print("Enter Employee Salary: ");

double salary = scanner.nextDouble();

scanner.nextLine();

Employee employee = new Employee(id, name, age, salary);

employees.add(employee);

try (PrintWriter writer = new PrintWriter(new FileWriter(FILE_NAME, true))) {

writer.println(employee);

} catch (IOException e) {

System.out.println("Error writing to file: " + e.getMessage());

}

}



private static void displayAllEmployees() {

System.out.println("--------------------------------------------");

for (Employee employee : employees) {

System.out.println(employee);

}

System.out.println("--------------------------------------------");

}

}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.