Showing posts with label PROGRAMS. Show all posts
Showing posts with label PROGRAMS. Show all posts

Multiple inheritance Program Code in Java

The code Below implements the concept of multiple inheritance.The program takes Roll number of student as input using one class. Then Marks obtained in two subject .Later the marks are added together along with bonus marks and total is printed.The code is implemented using multiple inheritance concept in mind.
You can use JDK or Netbeans IDE to run below code.

                                                                     
CODE:                                                                     
                                                                     
                                             
package mulinheritance;
import java.io.*;
	class student
	{
      	int rn;
  	void getNumber(int n)
  	{
      	rn = n;
 	 }
  	void putNumber()
  	{
   	   System.out.println("Roll Number: " +rn);
  	}
	}

	class test extends student
	{
    	float pt1, pt2;
 	void getMarks(float m1, float m2)
 	{
     	pt1 = m1;
     	pt2 = m2;
	 }
 	void putMarks()
 	{
     	System.out.println("<Marks Obtained>");
     	System.out.println("sports: " +pt1);
     	System.out.println("computer: " +pt2);
 	}
	}
 	interface theory
 	{
     	float theory= 10.0F;
     	void putWt();
	 }

	class result extends test implements theory
	{
    	float total;
    	public void putWt()
   	 {
      	 System.out.println("practical score: " +theory);
    	}
    	void display()
    	{
        total = pt1+pt2+theory;
        putNumber();
        putMarks();
        putWt();
        System.out.println("Total score: " +total);
       }
	}
	public class mulinheritance {
   	 public static void main(String[] args)throws Exception {
        try
        {
        result stud1 = new result();
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter the roll number: ");
        int num = Integer.parseInt(bf.readLine());
        stud1.getNumber(num);
        System.out.println("Enter the marks in sports: ");
        int ma = Integer.parseInt(bf.readLine());
        System.out.println("Enter the marks in computer: ");
        int sc = Integer.parseInt(bf.readLine());
        stud1.getMarks(ma,sc);
        stud1.display();
        }
        catch(Exception e) { }
        
    }

}


OUTPUT:                                                            
                                             
	Enter the roll number: 
	23
	Enter the marks in sports: 
	56
	Enter the marks in computer: 
	67
	Roll Number: 23
	<Marks Obtained>
	sports: 56.0
	computer: 67.0
	practical score: 10.0
	Total score: 133.0




Read more »

Java Program to Sort string in alphabetical order



Program complied with Netbeans IDE you can also use JDK and compile in command prompt .


PROGRAM:


package alphaorder;
import java.io.*;
import java.util.*;
public class alphaorder {
public static void main(String[] args)throws IOException {
BufferedReader st=new BufferedReader(new InputStreamReader(System.in));
String str;
System.out.println("Enter the string ");
str=st.readLine();
char[] charArray = str.toCharArray();
Arrays.sort(charArray);
String nstr = new String(charArray);
System.out.println("The sorted string is "+nstr);

}
}


OUTPUT:


Enter the string
dcba
The sorted string is abcd

Read more »