Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 9.7, Problem 9.7.2CP
Program Plan Intro
Given Program:
//class definition
public class Test {
// data members
int count;
// define main function
public ? void main(String[] args) {
...
}
// define getCount method
public ? int getCount() {
return count;
}
// define factorial method
public ? int factorial(int n) {
//data members
int result = 1;
for (int i = 1; i <= n; i++)
//calculate the factorial
result *= i;
//return statement
return result;
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
10.
public static void methodl (int i, int num) {
for (int j = 1; j <= i; j++) {
" ");
System.out.print (num +
num *= 2;
}
System.out.println();
}
public static void main(String[] args) {
int i = 1;
while (i <= 6) {
methodl (i, 2);
i++;
}
public void foo4() {
String s2 = "smith";
String s3 = s2;
String s4 = null;
String s5 = "";
String só = new String(s2);
if(s2 == s3) {
System.out.print("1");
}
if(s2.equals(s3)) {
System.out.print("2");
}
if(s2 == s6) {
System.out.print("3");
}
if(s2.equals(s6)) {
System.out.print("4");
}
if(s5 == s4) {
System.out.print("5");
}
if(s4.equals(s5)) {
System.out.print("6");
}
3//end of foo4()
Examine and trace the method foo4() above, which statement IS true?
O The method will print out "356" on screen.
The method will print out "1234" on screen.
The method will print out "123" on screen.
The method will print out "124" on screen.
class class
{
public static void main(String args[])
{
int a =5;
int b =10;
first:
{
second:
{
third:
{
if(a == b >>1)
break second;
}
System.out.println(a);
}
System.out.println(b);
}
}
}
Give result for the code
Java
Try to do ASAP
Chapter 9 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 9.3 - Prob. 9.3.1CPCh. 9.3 - How do you define a class?Ch. 9.3 - How do you declare an objects reference variable?Ch. 9.3 - How do you create an object?Ch. 9.4 - Prob. 9.4.5CPCh. 9.4 - When will a class have a default constructor?Ch. 9.5 - Which operator is used to access a data field or...Ch. 9.5 - What is an anonymous object?Ch. 9.5 - Prob. 9.5.3CPCh. 9.5 - Is an array an object or a primitive-type value?...
Ch. 9.5 - Prob. 9.5.5CPCh. 9.5 - What is wrong in the following code? 1. class Test...Ch. 9.5 - Prob. 9.5.7CPCh. 9.6 - Prob. 9.6.1CPCh. 9.6 - Prob. 9.6.2CPCh. 9.6 - Which packages contain the classes Date, Random,...Ch. 9.7 - Suppose the class F is defined in (a). Let f be an...Ch. 9.7 - Prob. 9.7.2CPCh. 9.7 - Can you invoke an instance method or reference an...Ch. 9.9 - Prob. 9.9.1CPCh. 9.9 - Prob. 9.9.2CPCh. 9.9 - In the following code, radius is private in the...Ch. 9.10 - Prob. 9.10.1CPCh. 9.10 - Show the output of the following program: public...Ch. 9.10 - Show the output of the following code:Ch. 9.10 - Prob. 9.10.4CPCh. 9.11 - What is wrong in the following code? 1public class...Ch. 9.12 - If a class contains only private data fields and...Ch. 9.12 - If all the data fields in a class are private and...Ch. 9.12 - Is the following class immutable? public class A {...Ch. 9.13 - What is the output of the following program?...Ch. 9.14 - Prob. 9.14.2CPCh. 9.14 - Prob. 9.14.3CPCh. 9 - (The Rectangle class) Following the example of the...Ch. 9 - (The Stock class) Following the example of the...Ch. 9 - (Use the Date class) Write a program that creates...Ch. 9 - Prob. 9.4PECh. 9 - (Use the GregorianCa1endar class) Java API has the...Ch. 9 - (Stopwatch) Design a class named StopWatch. The...Ch. 9 - (The Account class) Design a class named Account...Ch. 9 - (The Fan class) Design a class named Fan to...Ch. 9 - (Geometry: n-sided regular polygon) In an n-sided...Ch. 9 - Prob. 9.10PECh. 9 - (Algebra: 2 2linear equations) Design a class...Ch. 9 - (Geometry: intersecting point) Suppose two line...Ch. 9 - (The Location class) Design a class named Location...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- class operators { public static void main(String args[]) { int x = 8; System.out.println(++x * 3 + " " + x); } } Give result for the code Java Try to do ASAP ?arrow_forwardpublic class Test { } public static void main(String[] args) { String str = "Salom"; System.out.println(str.indexOf('t)); }arrow_forwardclass main { public static void main(String args[]) { int x =2; int y =0; for(; y <10;++y) { if(y % x ==0) continue; elseif(y ==8) break; else System.out.print(y +" "); } } } Give result for the code Java Try to do ASAParrow_forward
- public static int countIt (int n) { int count = 0; for (int i = n; i > 0; i /= 2) for (int j = 0; j < 10; j++) count += 1; return count; } Big-O notation: Explanation:arrow_forwardpublic class test{ private static final int MAX = 100; private int[] sco; public test(int[] sco){ this.sco = sco; } private int comAvg() throws IllegalArgumentException{ int sum = 0; for (int i = 0; i < sco.length; i++){ int sc = sco[i]; if (sc < 0 || sc > MAX){ throw new IllegalArgumentException("Score (" + sc + ") is not in the range 0-" + MAX); } sum += sco[i]; } int av = sum / sco.length; return av; } public static void main(String[] args){ test test = new test(new int[] { 50, 70, 81 }); try{ int avgSc = test.comAvg(); char letG; if (avgSc < 60) letG = 'F'; else if (avgSc < 70) letG = 'D'; else if (avgSc < 80) letG = 'C'; else if (avgSc < 90) letG = 'B'; else letG = 'A'; System.out.println("\nAVG Score is " +…arrow_forwardpublic class Course{String name;String dept;int number;public Course (String n, String d, int n){name = n;dept = d;number = n;}public String toString(){return "Course " + name + " in " + dept + " #: " + number;}public static void main (String [] args){Scanner in = new Scanner(System.in);add 10 lines using the scanner and saving them as strings The input for each line will be entered a String, a space, another String, and an int. Parse the input string into those three items and make an instance of Course. Add the new Course instance to a generic ArrayList of Course. print out each Course in the ArrayList.arrow_forward
- public class Number { private int num; public Number(int n) { num = n; } /* Type your code here */ public int getNum() { return num; } public void setNum(int n) { num = n; } public static void main(String [] args) { Number yourNum = new Number(723); System.out.print(yourNum); }}arrow_forwardclass Param3 { public int x; private void increase(int p) { x = x*p; } public void calculateX(int y) { increase(y); } public int getX() { return x; } } // in another class Param3 q3 = new Param3(); q3.x = 5; q3.calculateX(7); System.out.println(q3.getX()); what would be the answer for the last two lines ? also above were x = x*p do both x in here are the fields? wouldn't that be cnofusing?arrow_forward1- public class Con{ public static void main(String[] args) int[] ar=(2,5,7,9}; int i=2; final int j=1; 6. for (int x:ar) 8- { 9 if(ar[i]arrow_forwardpublic class Polygon { private double sideLength; private int sides; private String shape; public double getArea () { int n sides; double a sideLength; return ((a * a * n) / (4 * Math.tan((180 / n) 3.14159 / 180))); public void setPolygon (double sl, int sd, String sh) { sides-sd; sideLength-sl; shape=sh; public Polygon (double sl, int sd, String sh) ( sides-sd; sideLengthsl; shape=sh; public String getShape () { return (shape); } public int getSides () { return (sides); } public double getLength () { return (sideLength); } Write a static method named find that takes as a parameter an array of type Polygon named list. The method should print the shapes of each polygon that has an area greater than 500 and return their count. The method prototype is public static int find (Polygon [] list); Note: assume the array is already declared, populated with data in the main method and ready to be used.arrow_forwardclass overload { int x; double y; void add(int a , int b) { x = a + b; } void add(double c , double d) { y = c + d; } overload() { this.x 0; %3D this.y = 0; } %3D } class Overload_methods { public static void main(String args[]) { overload obj int a = 2; double b - 3.2; obj.add(a, a); obj.add(b, b); System.out.println(obj.x + } = new overload(); + obj.y); } #3Run the codearrow_forwardFix all logic and syntax errors. Results Circle statistics area is 498.75924968391547 diameter is 25.2 // Some circle statistics public class DebugFour2 { public static void main(String args[]) { double radius = 12.6; System.out.println("Circle statistics"); double area = java.Math.PI * radius * radius; System.out.println("area is " + area); double diameter = 2 - radius; System.out.println("diameter is + diameter); } }arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education