Concept explainers
a)
Explanation of Solution
Given code:
//declare the class showerrors
public class ShowErrors {
// main method
public static void main(String[] args) {
// create and initialize object
ShowErrors t = new ShowErrors(5);
}
}
Error in the code:
-
...
b)
Explanation of Solution
Given code:
//define the class showErrors
public class ShowErrors {
// define the main method
public static void main(String[] args) {
// new object gets created
ShowErrors t = new ShowErrors();
// object access method x
t...
c)
Explanation of Solution
Given code:
//new class gets defined
public class ShowErrors
{
//define the method
public void method1()
{
//circle class with object c
Circle c;
//display the radius
System.out.println("What is radius " +
c...
d)
Explanation of Solution
Given code:
//new class showerror gets defined
public class ShowErrors {
// define the main method
public static void main(String[] args) {
// class c and object gets initialized
C c = new C(5.0);
// display the value of c
System.out.println(c.value);
}
}
// class c
class C {
// assign the value
int valu...
Trending nowThis is a popular solution!
Chapter 9 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- What is the output of the following code segment?arrow_forwardCode the following.arrow_forwardDO NOT USE EXISTING ANSWERS ON CHEGG OR COURSE HERO OR ANY OTHER SERVICES PLEASE! Thanks :) CODE IN PYTHON AND SHOW COMMENTS TO EXPLAIN CODE A confused Dutchman trying to speak English could say “I am in the war”, even though there is no hostile activity going on. The confusion1 here is that the English sentence “I am confused” is translated in Dutch as “Ik ben in de war”, which is phonetically (“sounding”) quite close to the first sentence. Such confusion leads to much enjoyment, but can complicate matters a bit. Given a sentence in Dutch and a dictionary containing both correct translations as well as phonetic (incorrect) translations of individual words, find the translation of the sentence and indicate whether it is correct, or in case there is more than one find the total number of correct and incorrect translations. A sentence is correctly translated when each word of the sentence is correctly translated. Input The input consists of: One line with an integer n (1≤n≤20), the…arrow_forward
- QUESTION One of the downsides of using expressions that produce results other than true or false is it is expensive to type-check it hurts readability since it may be confusion to know which route an execution will take. it can cause side effects skewing the results of the rest of the code it hurts writability since we have to write such long expressions.arrow_forwardSimplify each of the following regular expressions.arrow_forwardWhat is the screen output of the following codearrow_forward
- Please write clearly, thank youarrow_forwardQuestions:1. A criticism of the break and continue statements is that each is unstructured. These statements can always be replaced by structured statements. Describe in general how you’d remove any break statement from a loop in a program and replace it with some structured equivalent. [Hint: The break statement leaves a loop from within the body ofthe loop. Another way to leave is by failing the loop-continuation test. Consider using in theloop-continuation test a second test that indicates “early exit because of a ‘break’ condition.”] Use the technique you developed here to remove the break statement from the program of Fig. 5.13. 2. Write a program that uses for statements to print the following patterns separately, one below the other. Use for loops to generate the patterns. All asterisks (*) should be printed by a single statement of the form cout << '*'; (this causes the asterisks to print side by side). [Hint: The last two patterns require that each line begin with an…arrow_forwardPlease solve this C++ program as per ALL the instructions!!(Please read all the instructions and make sure to input the correct output as shown at the end of the pictures. Thank you for your help!(NOTE: DO NOT verify the validity of user input. You are supposed to use the POINTERS at different parts of the code as instructed Please do not write it any other way even if the output is same as shown.Instructions:Put the class definition in EV.h and the implementation of the constructors and functions in EV.cpp 1. Define a class called "EV", that represents the information of an electric vehicle. The EV is defined with these attributes: model (string), range(int), unit (string) and year (int). Functions of the EV class must perform the following operations: A default constructor which sets all the numeric instance variables to zero. A constructor with 4 parameters which sets the 4 instance variables to the corresponding values passed. Implement a getter function for each of the 4…arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning