#include <stdio.h> #define ROWS 3 #define COLS 3 void matrixMultiply(int *mat1, int *mat2, int *result, int rows1, int cols1, int cols2) { int i, j, k; // Multiplying matrices for (i = 0; i < rows1; i++) { for (j = 0; j < cols2; j++) { *(result + i * cols2 + j) = 0; for (k = 0; k < cols1; k++) { *(result + i * cols2 + j) += *(mat1 + i * cols1 + k) * *(mat2 + k * cols2 + j); } } } } void displayMatrix(int *mat, int rows, int cols) { int i, j; // Displaying matrix for (i = 0; i < rows; i++) { for (j = 0; j < cols; j++) { printf("%d\t", *(mat + i * cols + j)); ...
| SET 1 |
|---|
1.Write a Java program to create an applet to find the simple interest on a given amount, rate of interest and duration. Use proper GUI components in your program. import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
/**/
public class simpleinterest extends Applet{
Label l1,l2,l3,l4;
TextField t1,t2,t3;
Button b1;
Image picture;
public void init(){
picture = getImage(getCodeBase(),"20160613_091125.jpg"); //(set image same path)
l1=new Label("Enter the Amount ");
l2=new Label("Enter the Rate ");
l3=new Label("Enter interest Duration :");
l4=new Label("");
t1=new TextField();
t2=new TextField();
t3=new TextField();
b1=new Button("Chick here show result");
setLayout(null);
l1.setBounds(80,30,100,20);
t1.setBounds(250,30,100,20);
l2.setBounds(80,60,100,20);
t2.setBounds(250,60,100,20);
l3.setBounds(80,90,150,20);
t3.setBounds(250,90,100,20);
b1.setBounds(150,120,150,25);
l4.setBounds(150,150,150,25);
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b1);
add(l4);
t1.setForeground(Color.blue);
l1.setForeground(Color.red);
t2.setForeground(Color.green);
l2.setForeground(Color.pink);
t3.setForeground(Color.red);
l3.setForeground(Color.blue);
b1.addActionListener(new MyHandler());
}
public void paint(Graphics g) {
g.drawImage(picture, 0,0, this);
}
public class MyHandler implements ActionListener
{
public void actionPerformed( ActionEvent e)
{
int amount,rate,interest_time,simpleI;
amount=Integer.parseInt(t1.getText());
rate=Integer.parseInt(t2.getText());
interest_time=Integer.parseInt(t3.getText());
simpleI=(amount*rate*interest_time)/100;
l4.setText("simple Interest "+simpleI);
}
}
}
complie simpleinterest.javarun appletviewer simpleinterest.java |
| SET 2 |
2.Write a Java program to create an Account class. Define proper constructor for this class. Define methods for the following : (a) To display the account details. (b) To show the current balance. (c) To show the rate of interest . Make necessary assumptions, wherever required.*/ import java.util.*;
class Account{
String name;
int Account_balance=100000;
int withdraw;
int Current_balance;
double interest;
Account(){
System.out.print("Enter the Account holder Name: ");
Scanner in=new Scanner(System.in);
name=in.nextLine();
System.out.print("Enter the Withdrow Amount : ");
withdraw=in.nextInt();
}
void account_details(){
System.out.println("Show the Account Holdder Name : "+name);
}
void current_balance(){
if(withdraw>0 && 100000>=withdraw){
Current_balance=Account_balance-withdraw;
System.out.println("Show the Current Account Balance : "+Current_balance);
}
else{
System.out.println("Amount is insuficiant");
}
}
void Rate_interest(){
interest=Current_balance * 0.05;
System.out.println("Show the Interest Rate : 5%");
System.out.println("Show the with interest Amount: "+interest);
}
}
class Account1{
public static void main(String arg[]){
Account o1=new Account();
o1.account_details();
o1.current_balance();
o1.Rate_interest();
}
}
this file is save main class name save :Account1 complie :javac Account1.java Run :java Account1 |
| SET 3 |
3.Write a Java program to create a Vehicle class. Derive Car and Bus classes from the Vehicle class. Define appropriate constructors for all the three classes. Define methods to display vehicle details (including model, price, vehicle number). Make necessary assumptions, wherever required. import java.util.*;
class vehicle{
String type;
String model;
int price;
String number;
vehicle(String type_a,String model_a,int price_a,String number_a){
type=type_a;
model=model_a;
price=price_a;
number=number_a;
}
void desplay(){
System.out.println("........... "+type+"........");
System.out.println("model :"+model);
System.out.println("price :"+price);
System.out.println("vehicle number :"+number);
System.out.println("\n\n");
}
}
class bus extends vehicle{
bus(){
super("BUS DETAIL","model 2015",200000,"DL1254");
}}
class car extends vehicle{
car(){
super("CAR DETAIL","model 2016",1200000,"DL125456");
}}
class vehiclea{//main class
public static void main(String arg[]){
bus a2=new bus();
a2.desplay();
car a3=new car();
a3.desplay();
}
}
this file is save main class name save :vehiclea complie :javac vehiclea.java Run :java vehiclea |
| SET 4 |
4.Write a Java program to perform the following operations on string(s) : (a) To concatenate two strings (b) To find the length of a given string. (c) To convert a given string into upper case Solution:
import java.util.*;
//Write a Java program to perform the following operations on string(s) :
//(a) To concatenate two strings
//(b) To find the length of a given string.
//(c) To convert a given string into upper case
class string{
String s1="i am";
String s2="mannu";
String a1,a2,a3;
int len,len1;
void concatenate(){
a1=s1.concat(s2);
System.out.println("........To concatenate two strings.......\n");
System.out.println(" Add Two string : "+a1);
}
void stringlength(){
len=s1.length(); //string length is a function it is count space ex; i am
len1=s2.length(); //it's three word but cout space lengthis 4
System.out.println("\n\n..........String Length Find........");
System.out.printf("\n(i am) First String Length is "+len);
System.out.printf("\n(mannu) second string Length is "+len1);
}
void uppercase(){
a2=s1.toUpperCase();
a3=s2.toUpperCase();
System.out.println("\n\n.... To convert a given string into upper case....");
System.out.println("\n(i am) convert is string uppercase "+a2);
System.out.println("\n(mannu) convert is string uppercase "+a3);
}
}
class stringdesplay{
public static void main(String arg[]){
string o1=new string();
o1.concatenate();
o1.stringlength();
o1.uppercase();
}
}
this file is save main class name save :stringdesplay complie :javac stringdesplay.java Run :java stringdesplay |
Comments
Post a Comment