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

1 CSU41844.201 t.pdf t-content-rid-28284089 Do programming project 7.2 of the te

ID: 3692109 • Letter: 1

Question


1 CSU41844.201 t.pdf t-content-rid-28284089 Do programming project 7.2 of the text, as described here. Revise the student class of chapter 7. Each Student object should now also contain the scores for three tests. Make these of type int. Include two constructors in the class. One constructor takes the same parameters as the original Student class constructor, but initializes the three test scores each to zero: public Student (String first, String last, Address home, Address school) A second constructor has the same parameters as the original but adds three parameters for the test public Student (String first, String last, Address home, Address school, scores int scorel, int score2, Int score3 The new Student class implements the interface Score public interface Score public void setTestScore( int test Number, int score) public int getTestscore( int testNumber public int getAverage )i The testNumber is an integer 1, 2, or 3 and the score is the new value for that test score. If the testNumber is out of range the set method changes nothing and the get method returns 0. The getAverage method returns the average of the test scores. Use all three scores in the average (even if some are zero.) Modify the tostring0 method to include the test scores and average in the returned string Modify the tester method (called StudentBody) to create objects that now include test scores for john and marsha. Change some scores with the set method, then print out the final results using the toString tostring0 method In order to make things work you will also need a source file for the class Address. This does not need to be moified from what is in the book You will also need a source file Score.java for the interface (given above). Create a project in BlueJ that includes these classes. What to submit: submit source files for your modified student class, for the interface Score, and for your modified studentBody class. You will need the Address class, but this is the same as in the book so don't submit it Each source file you submit should have documentation at the top that gives the assignment name, your name, and date (as in previous assigments)

Explanation / Answer

import java.io.*;

class Student

{

int rollno;

String name, HomeAdrs, SchoolAdrs;

int no_of_sub;

int mark[];

Student(int roll,String Name,String H_adrs, String S_adrs,int subjects)throws IOException

{

rollno=roll;

name=Name;

HomeAdrs=H_adrs;

SchoolAdrs=S_adrs;

no_of_sub= subjects;

getMarks(subjects);

}

public void getMarks(int subjects ) throws IOException

{

mark=new int[subjects];

BufferedReader br= new BufferedReader (new InputStreamReader(System.in));

for (int i=0; i<subjects;i++)

{

System.out.println(“Enter “+i+”Subject Marks.:=> “);

mark[i]=Integer.parseInt(br.readLine());

System.out.println(“”);

}

}

public void calculateMarks()

{

double percentage=0;

String grade;

int tmarks=0;

for (int i=0;i<mark.length;i++)

{

tmarks+=mark[i];

}

percentage=tmarks/no_of_subjects;

System.out.println(“Roll Number :=> “+rollno);

System.out.println(“Name Of Student :=> “+name);

System.out.println(“Total marks :=> “+tmarks);

System.out.println(“Average Is :=> “+percentage);

}

}

class StudentDemo

{

public static void main(String args[])throws IOException

{

int rno,n, nostud,sub1,sub2,sub3;

String name,Hadrs,Sadrs;

BufferedReader br= new BufferedReader (new InputStreamReader(System.in));

System.out.println(“Enter How many Students:=> “);

nostud=Integer.parseInt(br.readLine());

Student s[]=new Student[nostud];

for(int i=0;i<nostud;i++)

{

System.out.println(“Enter Roll Number:=> “);

rno=Integer.parseInt(br.readLine());

System.out.println(“Enter Name:=> “);

name=br.readLine();

System.out.println(“Enter Houseadress:=> “);

Hadrs=br.readLine();

System.out.println(“Enter Schooladress:=> “);

Sadrs=br.readLine();

System.out.println(“Enter No of Subject:=> “);

n=Integer.parseInt(br.readLine());

s[i]=new Student(rno,name,Hadrs,Sadrs,n);

}

for(int i=0;i<nostud;i++)

{

s[i].calculateMarks();

}

}

}

note-the above code can help to answer the given question.