Java Programming: Solving Problems with Software Coursera Quiz answers

In this post, you will get all weeks quiz answers of Java Programming: Solving Problems with Software Coursera.

Crash Course on Python Coursera all modules assignment answers

Enroll Here: Java Programming: Solving Problems with Software – Coursera

Course overview (All weeks quizzes answers link)

Java Programming: Solving Problems with Software Coursera Quiz answers

Shortcut to Search any random question:

Desktop users: ctrl + F
Mobile users: Click on 3 dots ( â‹® visible on top left of browser) -> Go to “Find in Page” -> Enter question

Now, let’s start with Week 1 quiz answers which is a part of Java Programming: Solving Problems with Software

Week 1: Java Programming: Solving Problems with Software Coursera Quiz answers

Below you’ll find all practice quiz answers of different topics/sections in Java Programming: Solving Problems with Software Coursera Quiz answers and end quiz exam answers under week 1.

Practice Quiz: Getting Started with BlueJ Quiz Answers Coursera – 3 questions

Q1: Suppose you have written a Java program that has one class and one method. Which one of the following best describes what you need to do in order to run the program?

a) Compile the program, create a new object for the class, and call the method.
b) Compile the program, call the method, and then create a new object for the class.
c) Create a new object for the class, compile the program, and call the method.
d) Create a new object for the class, call the method, and then compile the program.

Answer: a) Compile the program, create a new object for the class, and call the method.

Q2. Which one of the following best describes what happens when one compiles a Java program in BlueJ on their computer?

a) Your Java program opens and processes the data files specified in your program.
b) The .class file is translated into a file that can be run on that computer.
c) The .java file is translated into a .class file that can be run on that computer.
d) A Java object is created that can be run on that computer.

Answer: c) The .java file is translated into a .class file that can be run on that computer.

Q3. Which one of the following best describes BlueJ?

a) BlueJ is a programming environment.
b) BlueJ is a word processor for editing code.
c) BlueJ is an object-oriented programming language.
d) BlueJ is software that organizes data files.

Answer: a) BlueJ is a programming environment.

OR

Q4. Which one of the following best describes how one knows in BlueJ that a class has compiled successfully?

a) The program automatically runs to indicate compilation success.
b) The class icon turns the color red to indicate compilation success.
c) An object is automatically created to indicate compilation success.
d) The class icon removes the shaded diagonal lines to indicate compilation success.

Answer: d) The class icon removes the shaded diagonal lines to indicate compilation success.

Practice Quiz: Variables and Mathematical Operators Quiz Answers Coursera – 3 questions

Q1. Consider the following Java statements.

int a = 5;
int b = 3;
int c = 4;
c = a + b;

What is the value of c after these lines execute?

Answer: 8

Q2. Consider the following Java statements.

int a = 1;
int b = a + 2;
int c = b + b;

What is the value of c after these lines execute?

Answer: 6

Q3. Consider the following Java statements.

int a = 3;
int b = 4 + a / 2;
int c = b % 3;

What is the value of c after these lines execute?

Answer: 2

Java Programming: Solving Problems with Software Coursera Quiz answers

Practice Quiz: Functions and Conditionals Quiz Answers Coursera – 3 questions

Q1. Before you start writing your own Java programs, it is important you fully understand what your Java code will do. Try solving the following problems in this quiz by hand.

Consider the following Java methods.

int f(int x) {
  return x*2 - 1;
}

int h() {
  int a = 3;
  int b = f(a) + f(4);
  return b;
}

What is the return value of the call h()?

Answer: 12

Q2. Consider the following method g.

int g (int a) {
  if (a < 9) {
    return 9;
  }
  
  if (a < 7) {
    return 7;
  }
  
  if (a < 4) {
    return 4;
  }
  
  return 0;
}

What is the value returned from the call g(5)?

Answer: 9

Q3. Consider the following method k.

int k (int a, int b) {
  if (a < b) {
    if (b > 4) {
      return 0 ;
    }
    else {
      return 1;
    }
  }
  else {
    if (a > 4) {
      return 2;
    }
    else {
      return 3;
    }
  }
}

For which of the values a and b would 2 be the return value?

a) a=2, b=0
b) a=1, b=3
c) a=6, b=8
d) a=6, b=6

Answer: d) a=6, b=6

Practice Quiz: Classes, Types, and For Each Loops Quiz Answers Coursera – 5 questions

Q1. Consider the following method play, and assume appropriate import statements are there for classes used in this function.

public void play () {
  Frog fred = new Frog();
  Cat jiang = new Cat();
  fred.hop(4);
  jiang.jump(5, fred);
  String greet = That is all";
  fred.say(greet, 3);
}

Without seeing any details of classes used in this program and their methods, but assuming the methods shown are valid methods for these classes, which one of the following are methods in the Frog class?

a) hop, jump and say
b) only jump
c) hop and say
d) only hop
e) only say

Answer: c) hop and say

Q2. Consider the following Java class.

public class Thing {
  
  private int a;
  
  public Thing(int x) {
    a = x;
  }
  
  public int geta() {
    return a;
  }
  
  public void print() {
    int b = 4;
    System.out.println(geta() + " " + b);
  }
}

Which method is the constructor?

a) geta
b) a
c) Thing
d) print

Answer: c) Thing

Java Programming: Solving Problems with Software Coursera Quiz answers

Q3. Consider the following class named Something that uses the edu.duke FileResource class.

public class Something {   
  
  public void run() {
    FileResource f = new FileResource("words.txt");
    for (String g : f.lines()) {
      System.out.println(g);
      System.out.println(g);
    }
  }
}

Suppose the file words.txt contains the following lines:

cat giraffe

bird

zebra

How many times is the for loop executed?

Answer: 3

Q4. Consider the following Java code segment.

int m = 7 ;
int n = 9 ;
double d = 4.5 ;
double f = 8.974 ;

Which one of the following arithmetic expressions would need a cast for the addition to work? (Hint: Review the video on Types if you are unsure what casting variables means.)

a) double w = d + f;
b) int y = n + f;
c) int x = m + n;
d) double z = m + f;

Answer: b) int y = n + f;

Q5. Consider the following Java class.

public class Thing {
  
  private int a;
  
  public Thing(int x) {
    a = x;
  }
  
  public int geta() {
    return a ;  
  }
  
  public void print() {
    int b = 4 ;
    System.out.println(geta() + " " + b);
  }
}

And consider the following code segment that uses the Thing class.

Thing f = new Thing(4);
System.out.println(f.geta());

Which one of the following is NOT a primitive type?

a) f
b) x
c) a
d) b

Answer: a) f

OR

Q6. Consider the following BlueJ program.

public class Mystery {
  
  /**
   * read file of mysterious phrases
   */
   
  public void DoSomething() {
    // initialize instance variables
    FileResource someFile = FileResource("phrases.txt");
    for (String phrase : someFile.lines()){
      System.out.println(phrase);
    }
  }
}

Which one of the following is the name of a method?

a) DoSomething
b) someFile
c) Mystery
d) phrase

Answer: a) DoSomething

Java Programming: Solving Problems with Software Coursera Quiz answers

Q7. Consider the following Java class.

public class Thing {
  
  private int a;
  
  public Thing(int x) {
    a = x;
  }
  
  public int geta() {
    return a;
  }
  
  public void print() {
    int b = 4;System.out.println(geta() + " " + b);
  }
}

What is (or are) the instance variable(s) in this class?

a) a and x
b) a, x, and b
c) a
d) x
e) b

Answer: c) a

Q8. Consider the following Java class.

public class Thing {
  
  private int a;
  
  public Thing(int x) {
    a = x;
  }
  
  public int geta() {
    return a;
  }
}

And consider the following code segment that uses the class Thing.

Thing f = new Thing(3);
Thing g = new Thing(5);
Thing h = f;
Thing j = h;

How many Thing objects are created?

Answer: 2

Q9. Consider the Thing class shown below.

public class Thing {
  
  private int a;
  
  public Thing(int x) {
    a = x;
  }
  
  public int geta() {
    return a ;
  }
  
  public void combine (Thing y) {
    a = a + y.geta();
  }
}

And consider the following code segment that uses the Thing class.

Thing f = new Thing(6);
Thing g = new Thing(8);
f.combine(g);
System.out.println(f.geta());
System.out.println(g.geta());

What is printed when this code is executed?

a) 14
14

b) 6
8

c) 14
8

d) 6
14

Answer: c) 14
8

WEEK 1 QUIZ

Calculating the Perimeter of a Shape Week 1 Quiz Answers Coursera – 7 questions

This is the end quiz of week 1 in Java Programming: Solving Problems with Software Coursera Quiz answers. It is necessary to complete with 80% or higher.

Q1. What is the perimeter of the shape made from the file datatest1.txt whose contents are shown below (just give to two decimal places)?
-3, 3
-4, -3
4, -2
6, 5

Answer: 30.64

Q2. What is the average length of a side in the shape made from the file datatest1.txt whose contents are shown below (just give to two decimal places)?
-3, 3
-4, -3
4, -2
6, 5

Answer: 7.66

Q3. What is the longest side in the shape made from the file datatest4.txt whose contents are shown below (just give to two decimal places)?
-3, 9
8, 7
-12, 4
-6, -2
-4, -6
2, -8
6, -5
10, -3
8, 5
4, 8

Answer: 8.48

Q4. What is the largest perimeter of a shape made from the shapes in files dataset1.txt, dataset2.txt, dataset3.txt, dataset4.txt, dataset5.txt, and dataset6.txt (just give to two decimal places)?

Answer: 62.65

Q5. What is the name of the file that has the shape with the largest perimeter from the six files dataset1.txt, dataset2.txt, dataset3.txt, dataset4.txt, dataset5.txt, and dataset6.txt?

a) dataset1.txt
b) dataset2.txt
c) dataset3.txt
d) dataset4.txt
e) dataset5.txt
f) dataset6.txt

Answer: e) dataset5.txt

Q6. The method getNumPoints returns the number of points in a Shape s.

Which one of the following is NOT a correct implementation of getNumPoints?

a)  public int getNumPoints (Shape s) {
      int count = 0;
      for (Point p : s.getPoints()) {
         int newPoint = 1;
         count = count + newPoint;
      }
      return count;
    }

b)  public int getNumPoints (Shape s) {
       int count = 0;
       int newPoint = 1;
       for (Point p : s.getPoints()) {
          count = count + newPoint;
       }
       return count;
    }

c)  public int getNumPoints (Shape s) {
       int count = 0;
       for (Point p : s.getPoints()) {
          count = count + 1;
       }
       return count;
    }

d)  public int getNumPoints (Shape s) {
        int count = 0;
        for (Point p : s.getPoints()) {
           count = count + count;
        }
        return count;
    }

Answer: d)

Q7. Consider the following code for the function mysteryShape that has one parameter a Shape s and calls the function getNumPoints from the assignment.

public double mysteryShape (Shape s) {
  double tmp = 0;
  for (Point p : s.getPoints()) {
    
    if (p.getX() > 0) {
      
      if (p.getY() < 0) {
        tmp = tmp + 1;
      }
    }
  }
  return tmp / getNumPoints(s);    
}

Which one of the following best describes the purpose of this function?

a) The function computes the sum of those points from the Shape s that have a positive X or a negative Y.
b) The function computes the sum of those points from the Shape s that have a positive X and a negative Y.
c) The function computes the percentage of those points from the Shape s that have a positive X or a negative Y.
d) The function computes the percentage of those points from the Shape s that have a positive X and a negative Y.

Answer: d) The function computes the percentage of those points from the Shape s that have a positive X and a negative Y.

OR

Q8. What is the name of the file that has the shape with the largest perimeter from the four files example1.txt, example2.txt, example3.txt and example4.txt?

Answer: example3.txt

Q9. What is the perimeter of the shape made from the file database4.txt whose contents are shown below (just give to two decimal places)?
-3, 9
8, 7
-12, 4
-6, -2
-4, -6
2, -8
6, -5
10, -3
8, 5
4, 8

Answer: 59.45

Q10. What is the average length of a side in the shape made from the file datatest4.txt whose contents are shown below (just give to two decimal places)?
-3, 9
8, 7
-12, 4
-6, -2
-4, -6
2, -8
6, -5
10, -3
8, 5
4, 8

Answer: 5.94


>> Next: WEEK 2: Java Programming: Solving Problems with Software Coursera Quiz answers

Crash Course on Python Coursera all modules assignment answers

Explore! Artificial Intelligence Foundations Exams answers – SkillUp

The above question set contains all the correct answers. But in any case, you find any typographical, grammatical or any other error then kindly inform us.

Thanks in advance.

For discussion about any question, join the below comment section. And get the solution of your query. Also, try to share your thoughts about the topics covered in this particular quiz.

Leave a Comment

Your email address will not be published. Required fields are marked *