You have to design your own Java console application about any valid problem that your application must solve. Your solution can include solving a business problem, a new idea or even a game. Your application must make use of concepts such as arrays, loops, inheritance, constructors and information hiding. Output must be shown in the form of a report using the console. In your solution, make use of as many concepts, and components dealt with in this course, but pay special attention to the following: Advanced arrays and Introduction to inheritance.
package student;
import java.util.Scanner;
public class Student {
private String name; //Information hiding
private int rollNumber;
private int age;
public Student(){
}
public Student(String n, int r, int a){
name = n;
rollNumber = r;
age = a;
}
String getName(){
return name;
}
int getRollNumber(){
return rollNumber;
}
int getAge(){
return age;
}
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter name of the student\n");
String name = scan.next();
System.out.println("Enter roll number of the student\n");
int roll = scan.nextInt();
System.out.println("Enter age of the student\n");
int age = scan.nextInt();
Test t = new Test(name, roll, age, 10);
t.inputMarks();
t.display();
}
}
//Inheritance
class Test extends Student{
Scanner scan = new Scanner(System.in);
private int[] arr; //Advanced arrays
private int total_marks;
public Test(String n, int r, int a, int m){
super(n, r, a);
total_marks = 5;
arr = new int [total_marks];
}
void inputMarks(){
System.out.println("Enter 5 marks of the student\n");
for(int i=0; i<total_marks; i++){
System.out.printf("Mark %d\n", (i+1));
int mark = scan.nextInt();
arr[i] = mark;
}
}
void display(){
System.out.println("Name: \n" +getName());
System.out.println("Roll Number: \n" +getRollNumber());
System.out.println("Age: \n" +getAge());
float sum = 0;
for(int i=0; i<total_marks; i++){
System.out.printf("Mark %d is: %d\n", (i+1), arr[i]);
sum += arr[i];
}
System.out.printf("Total marks is: %f\nAverage mark is %f", sum, sum /5);
}
}
Comments
Leave a comment