-Learning Catalytics × / * Homework7-CS-1 : x Chegg Study l Guide × 4. My Drive-
ID: 3688614 • Letter: #
Question
-Learning Catalytics × / * Homework7-CS-1 : x Chegg Study l Guide × 4. My Drive-Google [ × Family Tree Omar-( × Unit 3 Essay-Goog -Course Home https://learn.ou.edu/d21/le/content/2152401/viewContent/3534252/View M Inbox-bryan·sando × (4 points each) Write the necessary lines of code to call the following methods that are part of the School object and store any results based on their signatures. The School object has a constructor that takes in one value: an integer identifying the School. For this example, you can use the 12345 for this integer. 4. a. int| getGrades0 b. void ringBell0 c. double getAverage(intl grades d. Stringl getPrintQueue(int maxLength) 5. (8 points) How do each of these method calls change if the word "static" is added to the front of the signatures? You can write one sentence describing it, or re-write the four method calls below to be static. View as Text 12:20 PM 4/12/2016 Search WindowsExplanation / Answer
SolutionDem.java
class Solution {
int[] grades = {100, 90, 80};//array declaration and assiginiing
int[] getGrades() {//instance method with array type signature or return type
for (int i = 0; i < grades.length; i++) {//this method displays all grades values
System.out.println("grades[" + i + "] =" + grades[i]);
}
return grades;
}
void ringbell() {//instance method with void return type
System.out.println("Bell rang");
}
double getaverage(int[] grades) {//this method get average
int tot = 0;
float avg = 0.0f;
int len = 0;
for (int i = 0; i <grades.length; i++) {
System.out.println("grades[" + i + "] =" + grades[i]);
tot = tot + grades[i];
len = grades.length;
}
avg = tot / len;
System.out.println(" average=" + avg);
return avg;
}
String[] getPrintQueue(int maxlength) {//this instance method print string array printqueue[i]
//and having return type string array
String[] printQueue = {"hello", "my", "name", "powerstar"};
for (int i = 0; i < maxlength; i++) {
System.out.print(printQueue[i]);
}
return printQueue;
}
}
public class SolutionDemo {//main method
public static void main(String args[]) {
int[] grades = {100, 90, 80};//grade values
Solution s = new Solution();//for calling instance method we have to create object
System.out.println("calling get grades method i.e int[] getGrades()");
s.getGrades();
System.out.println("calling s.ringbell()method");
s.ringbell();
System.out.println("");
System.out.println("calling String[] getPrintQueue(int maxlength) method ");
s.getPrintQueue(4);
System.out.println("");
System.out.println(" calling double getaverage(int[] grades) method ");
s.getaverage(grades);
System.out.println("");
System.out.println("calling static method i.e int[] getGrades()");
SolutionDemo.getGrades();//calling static method
System.out.println("");
System.out.println("calling static method double getaverage(int[] grades) method ");
SolutionDemo.getaverage(grades);
System.out.println("calling static method s.ringbell()");
SolutionDemo.ringbell();//calling static method
System.out.println("");
System.out.println("calling static method String[] getPrintQueue(int maxlength) ");
SolutionDemo.getPrintQueue(4);
System.out.println("");
}
static int[] getGrades() {
int[] a = {100, 90, 80};
for (int i = 0; i < a.length; i++) {
System.out.print("a[" + i + "] =" + a[i]);
}
return a;
}
static void ringbell() {
System.out.println("Bell rang");
}
static double getaverage(int[] grades) {
int[] a = {100, 90, 80};
int tot = 0;
float avg = 0.0f;
int len = 0;
for (int i = 0; i < a.length; i++) {
System.out.println("a[" + i + "] =" + a[i]);
tot = tot + a[i];
len = a.length;
}
avg = tot / len;
System.out.println("get average=" + avg);
return avg;
}
static String[] getPrintQueue(int maxlength) {
String[] printQueue = {"hello", "my", "name", "powerstar"};
for (int i = 0; i < maxlength; i++) {
System.out.println(printQueue[i]);
}
return printQueue;
}
}
output
run:
calling get grades method i.e int[] getGrades()
grades[0] =100
grades[1] =90
grades[2] =80
calling s.ringbell()method
Bell rang
calling String[] getPrintQueue(int maxlength) method
hellomynamepowerstar
calling double getaverage(int[] grades) method
grades[0] =100
grades[1] =90
grades[2] =80
get average=90.0
calling static method i.e int[] getGrades()
a[0] =100a[1] =90a[2] =80
calling static method double getaverage(int[] grades) method
a[0] =100
a[1] =90
a[2] =80
get average=90.0
calling static method s.ringbell()
Bell rang
calling static method String[] getPrintQueue(int maxlength)
hello
my
name
powerstar
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.