Create a program where 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. Use Advanced arrays & Introduction to inheritance
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
StudentResults st = new StudentResults(12, "Isiah", 3);
st.getSubjects();
st.displayMarks();
}
}
class Student{
private int rollNo;
private String name;
public Student(int roll, String n){
rollNo = roll;
name = n;
}
public void display(){
System.out.printf("Name: %s\nRoll Number: %d", name, rollNo);
}
}
class StudentResults extends Student{
private int[] marks;
private int number;
StudentResults(int roll, String n, int s){
super(roll, n);
number = s;
marks = new int[number];
}
void getSubjects(){
Scanner scan = new Scanner(System.in);
System.out.println("Enter the three subjects of the student");
for (int i=0; i<number ; i++ ) {
System.out.println("Subject: "+ (i+1) );
marks[i] = scan.nextInt();
}
}
void displayMarks(){
display();
System.out.println();
for (int i=0; i<number ; i++ ) {
System.out.println(marks[i]);
}
}
}
Comments
Leave a comment