Assignment 3-5 - 110100
Assignment 3-5 - 110100
SET A
A1
interface Continent {
String getContinentName();
String continentName;
String countryName;
this.continentName = continentName;
this.countryName = countryName;
@Override
return continentName;
return countryName;
String stateName;
String placeName;
State(String continentName, String countryName, String stateName, String placeName) {
super(continentName, countryName);
this.stateName = stateName;
this.placeName = placeName;
return stateName;
return placeName;
place.displayDetails();
}
A2
import java.util.Scanner;
// Parameterized constructor
this.id = id;
this.name = name;
// Subclass OfficeStaff
// Parameterized constructor
this.department = department;
void displayDetails() {
System.out.println("--------------------------");
int n = scanner.nextInt();
int id = scanner.nextInt();
staff.displayDetails();
scanner.close();
A3
import java.util.Scanner;
interface Operation {
double PI = 3.142;
// Abstract methods
double area();
double volume();
}
class Cylinder implements Operation {
this.radius = radius;
this.height = height;
@Override
// Area of a cylinder = 2 * PI * r * (r + h)
@Override
A4
import java.util.Scanner;
@FunctionalInterface
interface Cube {
System.out.println("Enter a number:");
SET B
B1]
import java.util.Scanner;
int id;
String description;
public Order()
this.id=0;
this.description=" ";
this.id=id;
this.description=description;
String customerName;
public PurchaseOrder()
super();
this.customerName="";
super(id,description);
this.customerName=customerName;
void accept()
id=sc.nextInt();
sc.nextLine();
description=sc.nextLine();
customerName=sc.nextLine();
void display()
{
System.out.printf("%-5d|%-25s|%-20s|\n",id,description,customerName);
String vendorName;
public SalesOrder()
super();
this.vendorName=" ";
super(id,description);
this.vendorName=vendorName;
void accept()
id=sc.nextInt();
sc.nextLine();
System.out.print("Enter description:");
description=sc.nextLine();
vendorName=sc.nextLine();
}
void display()
System.out.printf("|%-5d|%-25s|%-20s|\n",id,description,vendorName);
public class B1
po1.accept();
po2.accept();
po3.accept();
so1.accept();
so2.accept();
so3.accept();
System.out.println("-----------------------------------------------------");
po1.display();
po2.display();
po3.display();
System.out.println("------------------------------------------------------");
so1.display();
so2.display();
so3.display();
B2]
import java.util.*;
interface MarkerInt{
int pid,pcost,quantity;
String pname;
product()
//DefaultConstructor
pid=1;
pcost=10;
quantity=1;
pname="Pencil";
cnt++;
//Parametrized constructor
this.pid=pid;
this.pname=pname;
this.pcost=pcost;
this.quantity=quantity;
cnt++;
void display()
System.out.println("|\t"+pid+"\t"+pname+"\t"+pcost+"\t\t"+quantity+"\t|");
public class B2
int n=sc.nextInt();
for(int i=0;i<n;i++)
int pid=sc.nextInt();
sc.nextLine();
System.out.println("Enter Product Name : ");
String pn=sc.nextLine();
int pc=sc.nextInt();
int pq=sc.nextInt();
p[i]=new product(pid,pn,pc,pq);
System.out.println("|\tPID\tPname\tCost\tQuantity\t|");
for(int i=0;i<n;i++)
p[i].display();
sc.close();
SET C
import java.util.Scanner;
interface Department
void displayDept();
class Hostel
String hostelName;
String hostelLocation;
int noOfRooms;
public Hostel( String hostelName ,String hostelLocation, int noOfRooms)
this.hostelName = hostelName;
this.hostelLocation = hostelLocation;
this.noOfRooms = noOfRooms;
String studentName;
String regNo;
String electiveSubject;
double avgMarks;
this.studentName = studentName;
this.regNo = regNo;
this.electiveSubject = electiveSubject;
this.avgMarks = avgMarks;
}
displayHostel();
displayDept();
public class C1
inp.nextLine();
inp.nextLine();
if(student == null)
}
else
student.hostelName = inp.nextLine();
student.hostelLocation = inp.nextLine();
student.noOfRooms = inp.nextInt();
inp.nextLine();
if(student == null)
else
student.displayDetails();
int choice;
do
System.out.println("\nMenu\n1. Admit new student \n2. Migrate student \n3. Display student
details \n4. Exit");
choice = inp.nextInt();
inp.nextLine();
switch(choice)
}while(choice !=4);
ASSIGNMENT 4
SET A
1]
import java.util.Scanner;
CovidPositiveException(String message) {
super(message);
}
}
class Patient {
String patient_name;
int patient_age;
double patient_oxy_level;
int patient_HRCT_report;
// Constructor
this.patient_name = name;
this.patient_age = age;
this.patient_oxy_level = oxyLevel;
this.patient_HRCT_report = hrctReport;
} else {
displayInfo();
void displayInfo() {
System.out.println("enter name");
System.out.println("enter age");
try {
patient.checkCondition();
} catch (CovidPositiveException e) {
System.out.println(e.getMessage());
} finally {
}
}}
2]
import java.io.*;
if (!f.exists()) {
System.exit(0);
try {
String line;
System.out.println(line.toUpperCase());
content.append(line).append("\n");
buf_reader.close();
// Display contents in reverse order
System.out.println(content.reverse().toString());
} catch (IOException e) {
3]
import java.io.*;
if (args.length < 2) {
System.exit(0);
if (!sourceFile.exists()) {
System.exit(0);
try {
String line;
// Read from the source file and write to the destination file
buf_writer.write(line);
buf_writer.newLine();
buf_writer.write("end of file");
buf_reader.close();
buf_writer.close();
} catch (IOException e) {
SET B
2]
import java.util.Scanner;
super(message);
super(message);
public class B2
String username;
String password;
public B2()
this.username = "";
this.password = "";
if(!isValidUsername(username))
{
throw new InvalidUsernameException("Invalid Username : Username should be atleast 5
characters long.");
if(!isValidPassword(password))
this.username = username;
this.password = password;
return username.length()>=5;
}
public static void main(String[] args)
try
email.display();
catch(InvalidUsernameException exp)
System.out.println(exp.getMessage());
catch(InvalidPasswordException exp)
System.out.println(exp.getMessage());
3]
import java.util.Scanner;
class InvalidDateException extends Exception{
return msg;
class MyDate{
int day,mon,yr;
day=d;
mon=m;
yr=y;
void display(){
System.out.println("\n\t\tDate\n");
System.out.println("\t-------------");
System.out.println("\tDay\tMonth\tYear");
System.out.println("\t-------------");
System.out.println("\t"+day+"\t"+mon+"\t"+yr);
System.out.println("\t-------------");
public class b3
int day=sc.nextInt();
int mon=sc.nextInt();
int yr=sc.nextInt();
int flag=0;
try{
if(mon<=0||mon>12)
else{
if(mon==1||mon==3||mon==5||mon==7||mon==8||mon==10||mon==12)
if(day>=1&&day<=31)
flag=1;
else
}else if(mon==2){
if(yr%4==00){
if(day>=1&&day<=29)
flag=1;
else
}else{
if(mon==4||mon==6||mon==9||mon==11){
if(day>=1&&day<=30)
flag=1;
else
}
}
if(flag==1){
dt.display();
}catch(InvalidDateException e){
System.out.println(e);
ASSIGNMENT 5
SET A
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
JTextField display;
JPanel panel;
String cinput="";
double cresult=0.0;
public Calculator()
setTitle("Simple Calculator");
setLayout(new BorderLayout());
display=new JTextField(10);
display.setEditable(false);
add(display,BorderLayout.NORTH);
panel=new JPanel();
panel.setLayout(new GridLayout(4,4));
add(panel,BorderLayout.CENTER);
String[] buttonLabels={"1","2","3","+","4","5","6","-","7","8","9","*","0",".","=","/"};
for(String label:buttonLabels)
button.addActionListener(this);
panel.add(button);
if(command.equals("="))
if(!resultdisp)
calculateResult();
resultdisp=true;
else if(isOperator(command))
if(!resultdisp)
calculateResult();
}
lastop=command.charAt(0);
cinput="";
resultdisp=false;
else
cinput += command;
display.setText(cinput);
return "+-*/".contains(input);
try
double cvalue=Double.parseDouble(cinput);
switch(lastop)
break;
break;
break;
break;
break;
}
display.setText(Double.toString(cresult));
}catch(NumberFormatException e)
display.setText("Error");
calc.setSize(400,400);
calc.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
calc.setVisible(true);
SET B
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.text.AttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
public GUI() {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
// Your Name
inputPanel.add(nameField);
// Your Class
classPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
classPanel.add(classComboBox);
inputPanel.add(classPanel);
// Your Hobbies
hobbiesPanel.add(musicCheckBox);
hobbiesPanel.add(sportCheckBox);
hobbiesPanel.add(travellingCheckBox);
inputPanel.add(hobbiesPanel);
// Font Settings
fontPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
fontPanel.add(new JLabel("Font:"));
fontPanel.add(fontComboBox);
inputPanel.add(fontPanel);
// Font Size
sizePanel.setLayout(new FlowLayout(FlowLayout.LEFT));
sizePanel.add(new JLabel("Size:"));
sizePanel.add(sizeComboBox);
inputPanel.add(sizePanel);
// Font Style
stylePanel.setLayout(new FlowLayout(FlowLayout.LEFT));
stylePanel.add(new JLabel("Style:"));
stylePanel.add(boldCheckBox);
stylePanel.add(italicCheckBox);
stylePanel.add(underlineCheckBox);
inputPanel.add(stylePanel);
// Result Button
submitButton.addActionListener(new ActionListener() {
@Override
displayUserInformation();
});
inputPanel.add(submitButton);
frame.add(inputPanel, BorderLayout.NORTH);
resultTextPane.setEditable(false);
frame.pack();
frame.setVisible(true);
if (selectedFont != null) {
StyleConstants.setFontFamily(attributes, selectedFont);
try {
fontSize = Integer.parseInt(selectedSize);
} catch (NumberFormatException e) {
StyleConstants.setFontSize(attributes, fontSize);
if (boldCheckBox.isSelected()) {
fontStyle |= Font.BOLD;
if (italicCheckBox.isSelected()) {
fontStyle |= Font.ITALIC;
StyleConstants.setUnderline(attributes, true);
if (musicCheckBox.isSelected()) {
if (sportCheckBox.isSelected()) {
if (travellingCheckBox.isSelected()) {
hobbies += "Travelling";