Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Programming. Write ONE application program by using the following requireme

ID: 3694033 • Letter: J

Question

Java Programming. Write ONE application program by using the following requirements: File input and output, exception handling, you can create your own exception classes or you can using existing exception classes from Java API, Inheritance, at least one superclass or abstract superclass: this class needs to have data members, accessor, mutator, and toString methods, at least one subclass: this class also needs to have data members, accessor, mutator, and toString methods, at least one interface: this interface needs to have at least two abstract methods, at least one method overloading, at least one method overriding, at least one static member and one static method, Polymorphism: you need to have at least one superclass reference to reference objects of a subclass, at least one aggregation in a class. Please include comments at the place where you use the above items.

Please make only one program that contains all of these things. Thank you!

Explanation / Answer

Ans;

/*For any clarification, feel free to contact
If you like the lesson, kindly upvote
*/

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Automobile//superclass with accessor,toString, mutator and data fields

{
int year;
Automobile(int y)
{year=y;}
Automobile()
{year=0;
}

int getyear() {
return year;
}
public String toString(){return "Year : "+year;}
void setyear(int x){ year=x;}

}
interface onroadvehicle{//interface with abstract methods{

void printtype();
void printyear();

}
//Inheritence
public class Cars extends Automobile implements onroadvehicle//superclass with accessor,toString, mutator and data fields
{
String name; int year;
static String manufacturinglocation="Germany";//static field
Cars(String n,int y)
{
this.name=n;
this.year=y;

}
Cars(String n)//Method overloading
{
name=n;
year=0;

}
public String toString(){



return "Name : "+name+" Year:"+year+" Manufactured at : "+manufacturinglocation;


}
//static method
static void printmanulocation(){System.out.println("Manufactured at : "+manufacturinglocation);}
public void printtype() {

System.out.println("Cars");
}
public void printyear()
{
System.out.println("Year :"+year);

}
int getyear(){return year;}//method overriding
public static void main(String args[])
{
Cars c=new Cars("Vento",1999);
Automobile d=new Cars("Honda City",2001);
//Aggregation and superclass object reference of subclass type
System.out.println("1.Print Year 2.Print Manufacturing Location 3.Print complete data 4.Print class Type for Automobile ");
String str;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
//Exception handling
try {
str=br.readLine();
int x=Integer.parseInt(str);
if(x==1)
{c.printyear();}
if(x==2)
{
printmanulocation();
}
if(x==3)
{
System.out.println(c.toString());
}
if(x==4)
{
System.out.println(d.getClass());
}


} catch (IOException e) {

e.printStackTrace();
}


}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote