Question
JAVA QUESTION: Answer the following questions , considering the following code: Calling Class: Student Class: public static void main(String[] args) { Student mystudent=null; int score;
JAVA QUESTION:
Answer the following questions , considering the following code:
Calling Class: | Student Class: |
public static void main(String[] args) { Student mystudent=null; int score; try { mystudent = new Student(); mystudent.PostTest(74); mystudent.PostTest(83); } catch (Exception e) { System.out.println(e.getMessage()); System.exit(1); } score = mystudent.getAverage(); System.out.println(score); } | public class Student { int grade; int numtests ; public Student () { grade = 86; numtests = 1; } public Student (int intest) throws Exception { PostTest(intest); intest = (int)(intest * 1.1); PostTest(intest); numtests = 2; } public void PostTest(int x) throws Exception { grade = grade + x; if (x>120 || x<50) { Exception e=new Exception(Integer.toString(x)); throw e ;} numtests = numtests + 1; } public int getAverage() { return (grade/numtests) + 5;} private void PostTest(double y){ grade += y; return;} }
|
- What would be the output if the calling class was run?
- Assume bolded line (after the try keyword) was changed to mystudent = new Student(72);, what would be the output if the calling class was run?
- Assume bolded line (after the try keyword) was changed to mystudent = new Student(40);, what would be the output if the calling class was run?
- Could the calling class execute mystudent.PostTest(85.5)? Why or Why not?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started