Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
7th Edition
ISBN: 9780134802213
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 6, Problem 5FTE
Find the error in the following class:
public class FindTheError
{
public int square(int number)
{
return number * number;
}
public double square(int number)
{
return number * number;
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Analyze the following class, then choose the correct returnValueType for the method average.
void
int
String
double
COM.
Finish the following code so that every possible result of a die roll (sum = 2 to sum =12) happens >=1 time. Then, return how many rolls it took:
public class PoD{
//sum of the dice roll
public int gS(){
...
}
public void roll(){
...
}
public static int dG(PoD die){
boolean[] occurred = new boolean [12] //this is so we know the outcome of each roll
The following code is in Java:
public class Vehicle // Superclass
{
private double cost;
public Vehicle(double c)
{
cost = c;
}
(Other methods . . .) // assume these are given and they’re OK.
}
public class Car extends Vehicle // Subclass
{
private int passengers;
public Car(int p)
{
passengers = c;
}
(Other methods . . .) // assume these are given and they’re OK.
}
1) What problems are in the code above?2) What is needed to fix the issue of the code?
Chapter 6 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Ch. 6.1 - What does an object use its fields for?Ch. 6.1 - Prob. 6.2CPCh. 6.1 - How is a class like a blueprint?Ch. 6.1 - You have programs that create Scanner, Random, and...Ch. 6.1 - Prob. 6.5CPCh. 6.1 - What values do reference variables hold?Ch. 6.1 - Prob. 6.7CPCh. 6.2 - You hear someone make the following comment: A...Ch. 6.2 - Prob. 6.9CPCh. 6.2 - When a variable is said to reference an object,...
Ch. 6.2 - Prob. 6.11CPCh. 6.2 - Prob. 6.12CPCh. 6.2 - Prob. 6.13CPCh. 6.2 - Prob. 6.14CPCh. 6.2 - Prob. 6.15CPCh. 6.2 - What is a stale data item?Ch. 6.3 - Assume that r1 and r2 are variables that reference...Ch. 6.4 - How is a constructor named?Ch. 6.4 - What is a constructors return type?Ch. 6.4 - Prob. 6.20CPCh. 6.7 - Prob. 6.21CPCh. 6.7 - What is a methods signature?Ch. 6.7 - Look at the following class: public class...Ch. 6.7 - How many default constructors may a class have?Ch. 6.9 - Prob. 6.25CPCh. 6.9 - When designing an object-oriented application, who...Ch. 6.9 - How do you identify the potential classes in a...Ch. 6.9 - What are a classs responsibilities?Ch. 6.9 - What two questions should you ask to determine a...Ch. 6.9 - Will all of a classs actions always be directly...Ch. 6 - This is a collection of programming statements...Ch. 6 - A class is analogous to a(n) _______. a. house b....Ch. 6 - An object is a(n) ________. a. blueprint b....Ch. 6 - This is a class member that holds data. a. method...Ch. 6 - This key word causes an object to be created in...Ch. 6 - This is a method that gets a value from a classs...Ch. 6 - This is a method that stores a value in a field or...Ch. 6 - When the value of an item is dependent on other...Ch. 6 - This is a method that is automatically called when...Ch. 6 - When a local variable has the same name as a...Ch. 6 - This is automatically provided for a class if you...Ch. 6 - Prob. 12MCCh. 6 - Prob. 13MCCh. 6 - A classs responsibilities are __________. a. the...Ch. 6 - True or False: The new operator creates an...Ch. 6 - True or False: Each instance of a class has its...Ch. 6 - True or False: When you write a constructor for a...Ch. 6 - True or False: A class may not have more than one...Ch. 6 - True or False: To find the classes needed for an...Ch. 6 - Find the error in the following class: public...Ch. 6 - Prob. 2FTECh. 6 - The following statement attempts to create a...Ch. 6 - Find the error in the following class: public...Ch. 6 - Find the error in the following class: public...Ch. 6 - Design a class named Pet, which should have the...Ch. 6 - Look at the following partial class definition,...Ch. 6 - Consider the following class declaration: public...Ch. 6 - Look at the following description of a problem...Ch. 6 - The bank offers the following types of accounts to...Ch. 6 - Assume that you are writing an application that...Ch. 6 - What is the difference between a class and an...Ch. 6 - A contractor uses a blueprint to build a set of...Ch. 6 - What is an accessor method? What is a mutator...Ch. 6 - is it a good idea to make fields private? Why or...Ch. 6 - If a class has a private field, what has access to...Ch. 6 - Prob. 6SACh. 6 - Assume a program named MailList.java is stored in...Ch. 6 - Why are constructors useful for performing...Ch. 6 - Under what circumstances does Java automatically...Ch. 6 - What do you call a constructor that accepts no...Ch. 6 - Prob. 11SACh. 6 - How does method overloading improve the usefulness...Ch. 6 - Employee Class Write a class named Employee that...Ch. 6 - Car Class Write a class named Car that has the...Ch. 6 - Personal Information Class Design a class that...Ch. 6 - Retail Item Class Write a class named RetailItem...Ch. 6 - Payroll Class Design a Payroll class that has...Ch. 6 - TestScores Class Design a TestScores class that...Ch. 6 - Circle Class Write a Circle class that has the...Ch. 6 - Temperature Class Write a Temperature class that...Ch. 6 - Days in a Month Write a class named MonthDays, The...Ch. 6 - A Game of Twenty-One For this assignment, you will...Ch. 6 - Freezing and Boiling Points The following table...Ch. 6 - SavingsAccount Class Design a SavingsAccount class...Ch. 6 - Deposit and Withdrawal Files Use Notepad or...Ch. 6 - Patient Charges Write a class named Patient that...Ch. 6 - Dice Game Write a program that uses the Die class...Ch. 6 - Roulette Wheel Colors On a roulette wheel, the...Ch. 6 - Coin Toss Simulator Write a class named Coin. The...Ch. 6 - Tossing Coins for a Dollar For this assignment you...Ch. 6 - Fishing Game Simulation For this assignment, you...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Private Sub Handles btnOutput.Click
End Sub
Introduction To Programming Using Visual Basic (11th Edition)
In the chapter, we introduced a machine instruction of the form ODROS. Suppose we extended this form to OxDRXS,...
Computer Science: An Overview (12th Edition)
On what programming language was COBOL based?
Concepts of Programming Languages (11th Edition)
In Exercises 49 through 54, find the value of the given function. Math.Round(2.6)
Introduction to Programming Using Visual Basic (10th Edition)
Answer question 3.33, but do not consider any pet having the breed of Unknown.
Database Concepts (8th Edition)
Demonstrate each of the anomaly types with an example.
Modern Database Management
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 Param3 { public int y; public void method1(int y) { y = y * 3; } public int getY() { return y; } } Param3 q3 = new Param3(); q3.y = 100; q3.method1(25); System.out.println(q3.getY()); what is the output for the system.out.println method and whyarrow_forwardPig Laten: Pig Latin is a farcical "language" used to entertain children, but also to teach them some valuable language concepts along the way. Translating English to Pig Latin is simple: Your challenge is to implement the method `pigLatinize` that takes a string phrase and translates it to Pig Latin. You're free to add additional classes, variables, and methods if you would like.arrow_forwardThe BankAccount class described below is used to represent a personal savings account with a yearly interest rate, (represented as a percentage, e.g., a 7% rate is represented by .07). The interest is applied monthly, (i.e., at the end of each month 1/12 of the interest is deposited into the account). public class BankAccount { public BankAccount(double rate) public BankAccount(double initBal, double rate) public double getBalance() public double getIntRate() public void setIntRate(double rate) public void deposit(double amount) public void withdraw(double amount) public void addMonthsInterest() private double balance; private double intRate; } Suppose a bank offers to its special customers a new type of savings account, called a “Credit Account”, that allows the customer to withdraw extra money if needed, so that the account balance is allowed to be negative at some times. These accounts award interest at the end of every month, as long as the balance is positive. If the…arrow_forward
- Override the testOverriding() method in the Triangle class. Make it print “This is theoverridden testOverriding() method”. (add it to triangle class don't make a new code based on testOverriding in SimpleGeometricObject class.) (this was the step before this one) Add a void testOverriding() method to the SimpleGeometricObject class. Make it print“This is the testOverriding() method of the SimpleGeometricObject class”arrow_forwardprivate int b; public int method3() { return b; } // in another class an object of the first class was introduced and inside the second class : float y = tester.method3(); are there any errors ? and explain pleasearrow_forwardJava Methods Write a program that accepts three strings: first name, last name, age, and nationality. Create an object of the class Person and assign the inputs to their respective attributes. In the class, create a method greeting() that prints the attributes. Inputs 1. Input Cody Chum 20 Filipino Sample Output Enter first name: Cody Enter last name: Chum Enter age: 20 Enter nationality: Filipino Hello, I am Cody Chum, 20 years old and a Filipino!arrow_forward
- (Java) Question 3 Explain the answer step-by-step and include verbal explanation. Thank you! What will the following display to the console (don't run the code until you work it out by hand!) public class Person { String name; public Person(String name) { this.name = name; } public void printGreeting() { System.out.println("Hi, my name is, " + name + "!"); }}public class Student extends Person { double gpa; public Student(String name, double gpa) super(name); this.gpa = gpa; } public void printGreeting() { super.printGreeting(); System.out.println("My GPA of " + gpa + " is higher than yours!"); }}public class Test { public static void main(String[] args) { Person yan = new Person("Yan"); Person leann = new Student("Leann", 4.0); Student anh = new Student("Anh", 3.95); yan.printGreeting(); leann.printGreeting(); anh.printGreeting(); }}arrow_forwardExplain the following Java Polymorphism code in details.class Shape{public double getArea(){return 0.0;}}class Circle extends Shape{private int x,y;private double radius;public Circle(){x = y = 0;radius = 0.0;}public Circle(int x, int y, double radius){this.x=x;this.y=y;this.radius = radius;}public void drawShape(){System.out.println("Circle.drawShape()");}public double getArea(){double area = Math.PI* radius * radius;System.out.println("Circle area="+area);return area;}}class Rectangle extends Shape{private int x,y,h,w;public Rectangle(){x = y = h = w = 0;}public Rectangle(int x, int y, int h, int w){this.x=x;this.y=y;this.h=h;this.w=w;}public void drawShape(){System.out.println("Rectangle.drawShape()");}public double getArea(){double area = w * h;System.out.println("Rectangle area="+area);return area;}}public class ShapeTest{public static void main(String[] args) {Shape s = new Shape();Circle c = new Circle(0,0,10.0);Rectangle r = new Rectangle(0,0,5,4);System.out.println("Return…arrow_forwardIN JAVA Look at the following class definition: public class Dog {private int age = 0; // age is given in years, the default value is 0private String name = "Fido"; // default name is FidoDog(String firstName, int firstAge) {name = firstName;age = firstAge;if (age < 0) {age = 0;}}public void setName(String newName) {name = newName;}public int getAge() {return age;}public String getName() {return name;}public void haveBirthdayParty() {age = age + 1;System.out.println("Happy birthday " + name + "! You are now " + age + " years old!");}public void printInfo() {System.out.println("This dog's name is " + name + " and he's " + age + " years old!");}} Make a post containing your answers to all of the questions below: Can you create a new dog without specifying its name? Why or why not? Which of the Dog class's methods are accessors? Which ones are mutators? Can you use the methods provided to make a dog younger? (In other words, can you set age to a lower value than it already was?)…arrow_forward
- import java.util.*; class Money { private int dollar; private int cent; final static int MIN_CENT_VALUE = 0; final static int MAX_CENT_VALUE = 99; public Money() { this.dollar = 0; this.cent = 0; } public Money(int dollar, int cent) { this.dollar = dollar; if (cent > MIN_CENT_VALUE && cent <= MAX_CENT_VALUE) { this.cent = cent; } else { cent = 0; } } public int getDollar() { return this.dollar; } public void setDollar(int dol) { this.dollar = dol; } public int getCent() { return this.cent; } public void setCent(int c) { if (c >= MIN_CENT_VALUE && c <= MAX_CENT_VALUE) { this.cent = c; } } public Money add(Money otherMoney) { Money m = new Money(); m.dollar = this.dollar + otherMoney.dollar; m.cent = this.cent + otherMoney.cent; if (m.cent >= 100) {…arrow_forwardJava program Make a class Employee with a name and salary. Make a class Manager inherit from Employee. Add an instance variable, named department, of type String. Supply a method toString that prints the manager’s name, department, and salary. Make a class Executive inherit from Manager. Supply appropriate toString methods for all classes. Supply a test program that tests these classes and methods.arrow_forwardJava Questions - (Has 2 Parts). Based on each code, which answer out of the choices "A,B,C,D,E" is correct. Each question has one correct answer. Thank you. Part 1 - 3. Given the following code, the output is __. class Base { private int x = 5; }class Derived extends Base { x = 6; }public class Sample { public static void main(String[] args) { int x = 7; Derived d1 = new Derived(); System.out.print(d1.x); }} A. 0B. 5C. 6D. 7E. Error message Part 2 - 4. A class Animal has a subclass Mammal. Which of the following is true? A. class Animal extends Mammal { }B. class Mammal extends Animal { }C. class Animal implements Mammal { }D. class Mammal implements Animal { }E. class Mammal { Animal a1 = new Animal(); }arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
CPP Function Parameters | Returning Values from Functions | C++ Video Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=WqukJuBnLQU;License: Standard YouTube License, CC-BY