1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Roman55 [17]
3 years ago
5

If name is a String instance variable, average is a double instance variable, and numOfStudents is a static int variable, why wo

n’t the following code from a class compile?public Student(String s) {name = s;average = getAverage(name);numOfStudents++;}public double getAverage(String x) {numOfStudents++;double ave = StudentDB.getAverage(x);return ave;}public static void setAverage(double g) {average = g;}a.The setAverage() method can’t access the average instance variable.b.The getAverage() method can’t increment the numOfStudents variable.c.The constructor can’t increment the numOfStudents variable.d.The getAverage() method can’t call a static method in the StudentDB class.
Computers and Technology
1 answer:
IRINA_888 [86]3 years ago
7 0

Answer:

a.

Explanation:

Based solely on the snippet of code provided on the question the main reason why the code won't compile (from the options provided) is that the setAverage() method can’t access the average instance variable. Since the average variable is an instance variable it means that it only exists inside the one of the functions and not to the entire class. Meaning that in this scenario it can only be accessed by the Student function and once that function finishes it no longer exists. Also, it is not one of the options but if these variables are instance variables as mentioned their type needs to be defined inside the function.

You might be interested in
Words or symbols that help you narrow down your search are called:
timurjin [86]

Answer:

c) search operators

Explanation:

Words or symbols that help you narrow down your search are called search operators. This ultimately implies that, search operators are commands and special characters (words or symbols) which help users to filter and refine their search engine results by making the search more precise and specific in nature. Thus, search operators only provide search engine results that are relevant to what a user is searching for or it narrow down the focus of a search.

Hence, search operators comprises of commands and special characters (words or symbols) such as AND, OR, NOT, "", -, +, *, .., :, etc used for narrowing down search engine results.

For instance, typing "file.mp3" in a search engine would only present results that are in mp3 formats.

7 0
3 years ago
create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines.** Each m
jok3333 [9.3K]

Answer:

The Java code is given below

Explanation:

import java.io.*;

import java.util.Scanner;

import java.util.ArrayList;

public class StringCheck{

//There are several implementation approaches. This is one example framework/outline which might be helpful. Please feel free to try other approaches.

public static void checkWord(String word) throws Exception {

// Uses charAt method to test if the first letter of string variable word

// is a character. If not, throw new exception

if(Character.isLetter(word.charAt(0))){

 return;

}else{

 throw new Exception("This is not a word");

}

}

public static String getWord() {

// Declare a local scanner

// Prompt the user to enter a word

// Think about using a loop to give the user multiple opportunities to correctly enter a string

// Read into a string

// Call checkWord method passing the string as a parameter

// checkWord can throw an exception; call checkWord in a try/catch block

// Return the string to main if a valid string

Scanner sc = new Scanner(System.in);

boolean st = true;

String word = null;

while(st){

 System.out.println("Enter a Word : ");

 word = sc.next();

 try{

  checkWord(word);

  st = false;

 }catch(Exception e){

  System.out.println(e);

  st = true;

 }

}

sc.close();

return word;

}

public static void writeFile(String[] arrayToWrite, String filename) throws IOException {

// Example using FileWriter but PrintWriter could be used instead

// Create a FileWriter object

FileWriter fileWordStream = new FileWriter(filename);

// Use a loop to write string elements in arrayToWrite to fileWordStream

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

fileWordStream.write(arrayToWrite[i]+System.lineSeparator());

}

fileWordStream.flush();

fileWordStream.close();

// In the loop use the lineSeparator method to put each string on its own line

}

public static ArrayList readFile(String filename) throws FileNotFoundException, IOException {

// Declare local ArrayList

ArrayList<String> words = new ArrayList<>();

// Create a new File object using filename parameter

File file = new File(filename);

// Check if the file exists, if not throw a new exception

if(!file.exists()){

 throw new FileNotFoundException("File not Found");

}

// Create a new BufferedReader object      

Scanner fsc = new Scanner(file);

// use a loop and the readLine method to read each string (on its own line) from the file

while(fsc.hasNextLine()){

words.add(fsc.nextLine());

}

fsc.close();

// return the filled ArrayList to main

return words;

}

public static void main(String[] args) {

// create a string with literal values to write to the file

String[] testData = {"cat", "dog", "rabbit"};

// Create an ArrayList for reading the file

ArrayList<String> words = new ArrayList<>();

// Declare a string variable containing the file name "data.txt"

String file = "data.txt";

// Call getWord, assign the returned string to a variable and display it

String word = getWord();

System.out.println("The word is : "+word);

// Call writeFile and readFile methods in a try block

try{

writeFile(testData,file);

words = readFile(file);

// Printout the contents of the ArrayList after the call to readFile

for(int i = 0;i<words.size();i++){

 System.out.println(words.get(i));

}

}catch(FileNotFoundException e){

System.out.println(e);

}catch(IOException e){

System.out.println("IOException: error occured in input output");

}

// catch two types of exceptions

}

}

4 0
4 years ago
A computer with a single cpu has 4gb ram, with the operating system taking up 512mb and each user program also taking up 256mb.
lutik1710 [3]

Let's assume a condition where ram is 256 MB and the program size is more than 256 MB

in that case, CPU has to wait for I/O to load the remaining part of the program..in this case  

CPU utilization is much poorer.

So adding gives benefit only when your CPU is fast enough to take advantage like if a process waiting for I/O

it can put the current process in the run queue and take another process from the ready queue.

This way a better CPU utilization can be achieved.  

So by adding ram we can load more programs while waiting for I/O . CPU utilisation will be better.

here by adding 2GB ram we can load 2048/256 = 8 new process into ram at the same time.

2. if cpu have to execute the cpu bound process that wait for I/O cpu will be idle most of the time while  

waiting for I/O to be done..this way CPU utilization will be  poorer as compare to earlier.

3 0
3 years ago
Select the things you can do when working with rows in columns in a spreadsheet:
pantera1 [17]

Answer:

no uttar hai hai hai hai hai uara ke sook na mane yara मर aa

5 0
3 years ago
By applying styles, _______ formats are being applied each time. A. various B. different C. the same D. similar
Dmitry [639]
I just took the test on (PF) it's C. the same

i hope this helped someone.
;-)
4 0
4 years ago
Read 2 more answers
Other questions:
  • Which choice lists two image formats that support transparency
    6·2 answers
  • What determines the choice of a rocket for a mission?
    11·1 answer
  • What runs horizontally and is identified with numbers?
    12·2 answers
  • What specific tool allows you to create GPOs, view a GPO's settings, link and unlink GPOs with containers, and manage the inheri
    10·1 answer
  • In this lab, you will write a function called numberGuessingGame(). When the function is called, it will do the following: gener
    13·1 answer
  • Consider the following code segment. The code is intended to read nonnegative numbers and compute their product until a negative
    11·1 answer
  • In Java. Write a program that creates an integer array with 50 random values, prompts the user to enter the index of an element
    5·1 answer
  • SUMMING THE TRIPLES OF THE EVEN INTEGERS FROM 2 THROUGH 10) Starting with a list containing 1 through 10, use filter, map and su
    15·1 answer
  • Do you think the current video game industry is likely to experience another “crash” (similar to the one in the 1980s) any time
    10·1 answer
  • Which data type is used to teach a Machine Learning (ML) algorithm during structured learning?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!