0% found this document useful (0 votes)
56 views

Java Program - Convert Temperatures

1. The document contains 3 Java programming assignments. The first creates an outer class with a static and non-static inner class and demonstrates accessing variables between the classes. The second creates classes for students, marks, and results and shows output. The third creates an abstract vehicle class inherited by Car and Bike classes, with a static repair method to output repair details. 2. The first assignment creates an Outer1 class with a static Inner1 class and non-static inner class. It demonstrates accessing variables between the classes. The second assignment creates Student, Marks, and Percentage classes to store and output student name, id, subject marks, total, and percentage. The third assignment creates an abstract Vehicle class with concrete

Uploaded by

Nidhi Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views

Java Program - Convert Temperatures

1. The document contains 3 Java programming assignments. The first creates an outer class with a static and non-static inner class and demonstrates accessing variables between the classes. The second creates classes for students, marks, and results and shows output. The third creates an abstract vehicle class inherited by Car and Bike classes, with a static repair method to output repair details. 2. The first assignment creates an Outer1 class with a static Inner1 class and non-static inner class. It demonstrates accessing variables between the classes. The second assignment creates Student, Marks, and Percentage classes to store and output student name, id, subject marks, total, and percentage. The third assignment creates an abstract Vehicle class with concrete

Uploaded by

Nidhi Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

JAVA ASSIGNMENT 3

ROLL NO: 23
NAME: NIDHI SONI
1. Write Outer class Outer1 which include Static class StaticInner and non static inner
class NoStaticInner. Define variables in three classes. Demonstrate the access of all
variables
import java.util.Scanner;

public class demoinnerclass {

public static void main(String[] args)

{
// TODO Auto-generated method stub

Scanner s = new Scanner(System.in);


System.out.println("Enter the Value:");
int a=s.nextInt();
outer1.inner1 b=new outer1.inner1();
b.inner1(a);
b.display();

}
class outer1
{

public void outer1()


{
System.out.print(" Static Inner Class");
}

static class inner1


{
int n;

public void inner1(int n)


{

this.n=n;
}
public void display()
{
System.out.println("Number :"+n);
}
}

}
2. Create a student class with a name and id.

Marks class : 3 subjects marks m1,m2,m3 and total

Result class :percentage

Each class has a show() method that displays the details of students' data.

import java.util.Scanner;

public class demostudent {

public static void main(String[] args)


{
// TODO Auto-generated method stub

percentage p1=new percentage();


p1.add();
p1.sub();
p1.show();

}
class student
{
int id,m1,m2,m3,sum;
String name;
double per,average ;
void add()
{
Scanner s=new Scanner(System.in);
System.out.print("Enter Student Id:");
id=s.nextInt();
System.out.print("Enter Student Name:");
name=s.next();
}
}

class marks extends student


{

void sub()
{
Scanner s=new Scanner(System.in);
System.out.print("Enter Student Marks:");
m1=s.nextInt();
System.out.print("Enter Student Marks:");
m2=s.nextInt();
System.out.print("Enter Student Marks:");
m3=s.nextInt();
}
}

class percentage extends marks


{
void show()
{
sum=m1+m2+m3;
per=(sum*100)/300;
System.out.println("Total Marks:"+sum);
System.out.println("Percentage:"+per);
}
}

3. Create abstract class vehicle and define abstract as well as concrete method in this class. Inherit
this class into Car and Bike classes. Create a static method repair() in test class. Use this method to
repair either bike or car as per object passed.

import java.util.Scanner;

public class abstractdemo {

public static void main(String[] args)

{
// TODO Auto-generated method stub

bike b1=new bike();


repair(b1);
car c1=new car();
repair(c1);

}
public static void repair(vehicle v1)
{
v1.honda();
v1.hero();
}

abstract class vehicle


{
abstract void honda();
abstract void hero();
}
class car extends vehicle
{
void honda()
{
System.out.println("This Car Is Honda");
}
void hero()
{
System.out.println("This Car Is Hero");
}

class bike extends car


{
void honda()
{
System.out.println("This Bike Is Honda");
}
void hero()
{
System.out.println("This Bike Is Hero");
}
}

You might also like