java problem
java problem
import java.util.Arrays;
Arrays.sort(numericArray);
Arrays.sort(stringArray);
sum += value;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
arrayList.add(1);
arrayList.add(2);
arrayList.add(3);
arrayList.add(4);
arrayList.add(5);
import java.util.ArrayList;
arrayList.add("Apple");
arrayList.add("Banana");
arrayList.add("Cherry");
arrayList.add("Date");
}
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
this.numRows = numRows;
this.numColumns = numColumns;
this.elements = elements;
return numRows;
return numColumns;
elements[i][j] = value;
} else {
return null;
if (matrix1.getNumColumns() != matrix2.getNumRows()) {
return null;
int sum = 0;
resultElements[i][j] = sum;
System.out.println();
int numRows = 2;
int numColumns = 2;
int[][] matrix1Elements = {
{1, 2},
{3, 4}
};
int[][] matrix2Elements = {
{5, 6},
{7, 8}
};
System.out.println("Matrix 1:");
matrix1.displayMatrix();
System.out.println("\nMatrix 2:");
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
matrix2.displayMatrix();
System.out.println("\nAdding Matrices:");
if (sumMatrix != null) {
sumMatrix.displayMatrix();
System.out.println("\nMultiplying Matrices:");
int[][] matrix3Elements = {
{1, 2, 3},
{4, 5, 6}
};
int[][] matrix4Elements = {
{7, 8},
{9, 10},
{11, 12}
};
if (productMatrix != null) {
productMatrix.displayMatrix();
}
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
7. Write a program that has variables to store Car data like; CarModel,
CarName, CarPrice and CarOwner. The program should include functions to
assign user defined values to the above mentioned variable and a display
function to show the values. Write a main that calls these functions.
carModel = model;
carName = name;
carPrice = price;
carOwner = owner;
myCar.setCarModel("Mahindra Thar");
myCar.setCarName("4x4 M210021");
myCar.setCarPrice(2050000);
myCar.setCarOwner("Rohan sahu");
System.out.println("Car Information:");
myCar.displayCarInfo();
}
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
class Animal {
void makeSound() {
@Override
void makeSound() {
System.out.println("Dog barks.");
@Override
void makeSound() {
System.out.println("Cat meows.");
}
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
9. Write a program to create a class named shape. In this class we have three
subclasses: circle, triangle and square. Each class has two member functions
named draw () and erase (). Create these using polymorphism concepts.
class Shape {
void draw() {
}
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
void erase() {
@Override
void draw() {
System.out.println("Drawing a circle");
@Override
void erase() {
System.out.println("Erasing a circle");
@Override
void draw() {
System.out.println("Drawing a triangle");
@Override
void erase() {
System.out.println("Erasing a triangle");
@Override
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
void draw() {
System.out.println("Drawing a square");
@Override
void erase() {
System.out.println("Erasing a square");
circle.draw();
circle.erase();
triangle.draw();
triangle.erase();
square.draw();
square.erase();
}
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
interface A {
void meth1();
void meth2();
@Override
@Override
}
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
myClass.meth1();
myClass.meth2();
11. Create an outer class with a function display, again create another class
inside the outer class named inner with a function called display and call the
two functions in the main class.
class Outer {
void display() {
class Inner {
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
void display() {
outerObj.display();
innerObj.display();
String name;
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
int empid;
String category;
double bpay;
double hra;
double da;
double npay;
double pf;
double grosspay;
double incometax;
double allowance;
e.name = "John";
e.empid = 101;
e.category = "Manager";
e.bpay = 50000;
e.calculatePayroll();
}
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
13. Write a program in Java such that it accepts a number and displays the
square of the number 12 using applet. Create an input text field to accept a
number from user. Create a button to confirm the number and calculate its
square. When the button is clicked, display its square in a text field.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public SquareCalculator() {
setTitle("Calculate Square");
setLayout(null);
add(inputLabel);
add(numberField);
calculateButton.addActionListener(this);
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
add(calculateButton);
add(resultLabel);
resultField.setEditable(false);
add(resultField);
if (e.getSource() == calculateButton) {
try {
resultField.setText(String.valueOf(square));
resultField.setText("Invalid Input");
calculator.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
calculator.setSize(280, 180);
calculator.setVisible(true);
}
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public SimpleCalculator() {
setTitle("Simple Calculator");
setSize(300, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
display.setHorizontalAlignment(JTextField.RIGHT);
display.setEditable(false);
String[] buttonLabels = {
};
button.addActionListener(this);
buttonPanel.add(button);
add(display, BorderLayout.NORTH);
add(buttonPanel);
setVisible(true);
@Override
if (command.matches("[0-9]")) {
display.setText(display.getText() + command);
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
} else if (command.equals("C")) {
display.setText("");
num1 = 0;
num2 = 0;
} else if (command.equals("=")) {
num2 = Double.parseDouble(display.getText());
display.setText(String.valueOf(result));
num1 = result;
num2 = 0;
} else if (command.matches("[+\\-*/]")) {
num1 = Double.parseDouble(display.getText());
operator = command.charAt(0);
display.setText("");
switch (operator) {
case '+':
case '-':
case '*':
case '/':
if (num2 != 0) {
} else {
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
return 0;
default:
return num2;
}
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public SimpleRegistrationPage() {
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
registerButton.addActionListener(this);
panel.add(usernameLabel);
panel.add(usernameField);
panel.add(passwordLabel);
panel.add(passwordField);
panel.add(emailLabel);
panel.add(emailField);
panel.add(registerButton);
add(panel);
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109
setVisible(true);
@Override
if (e.getSource() == registerButton) {
}
CLASS : -SY BSC(IT) SUBJECT : - JAVA
DATE : - 7/11/2023 ENROLMENT : 2202040601109