// Please follow all the instructions
Each of the class declarations and/or member function definitions below has syntax error(s).
Find every error. All errors with explanation and fix the code.
* Hint: You may use compiler to help you find the error. However, you need to set up the program correctly and to point out the true cause of the syntax error. Because the compiler messages are convoluted, due to the convoluted nature of language dependencies.
54.
class Truck, public : Vehicle, protected { private: double cargoWeight; public: Truck(); ~Truck(); };
55.
class SnowMobile : Vehicle { protected: int horsePower; double weight; public: SnowMobile(int h, double w), Vehicle(h) { horsePower = h; } ~SnowMobile(); };
56.
class Table : public Furniture { protected: int numSeats; public: Table(int n) : Furniture(numSeats) { numSeats = n; } ~Table(); };
57.
class Tank : public Cylinder { private: int fuelType; double gallons; public: Tank(); ~Tank(); void setContents(double); void setContents(double);
58.
class Three : public Two : public One { protected: int x; public: Three(int a, int b, int c), Two(b), Three(c) { x = a; } ~Three(); };
54) correct answer:
class Truck : public Vehicle{
private:
double cargoWeight;
public:
Truck();
~Truck();
};
solution:
55)correct answer:
class SnowMobile : public
Vehicle
{
protected:
int horsePower;
double weight;
public:
SnowMobile(int h, double w):vehicle(h)
{
horsePower = h;
}
~SnowMobile();
};
solution:
56) correct answer:
class Table : public Furniture
{
protected:
int numSeats;
public:
Table(int n) : Furniture(n)
{
numSeats = n;
}
~Table();
};
solution:
Here, Base class Constructor can called inside Derived class. wrong parameter to the base class constructor ,it should be n instead of numseats
57)correct answer:
class Tank : public Cylinder{
private:
int fuelType;
double gallons;
public:
Tank();
~Tank();
void setContents(double);
void setContents(int);
void setContents(int,double);
};
solution: From the above code, there is a
duplication of setContents function so we can
eliminate the duplication here.
58) correct answer:
class Three : public Two, public One
{
protected:
int x;
public:
Three(int a, int b, int c): Two(b), Three(c)
{
x = a;
}
~Three();
};
solution:
// Please follow all the instructions Each of the class declarations and/or member function definitions below...
What is output? public abstract class People { protected string name; protected int age; public abstract void PrintInfo(); public void PrintInformation() { System.out.println("In Base Class People"); public class Teacher extends People { private int experience; public void PrintInfo() { System.out.println("In Child Class Teacher"); public class Principal extends Teacher { public void PrintInformation() { System.out.println("In Child Class Principal"); public static void main(String args[]) { Principal tim; tim = new Principal(); tim.PrintInfo(); In Base Class People Error: Compiler error In Child Class...
Java Programming CLASS DIAGRAM SECTION Please complete a rows in the table below. public class Polymorphism private protected int 21: double 22: //private protected Polymorphism. zl 2; public void addition (int x, int y) 21 y; System "The f an int and int "+zl void addition (double x, int y) 22 System.out.println ("InThe sum le and int +z2TF public void additi (int x, double y) 22 System out println ("InThe aum of an int and double +22 public void addition...
Requirements: Your Java class names must follow the names specified above. Note that they are case sensitive. See our template below. BankAccount: an abstract class. SavingAccount: a concrete class that extends BankAccount. o The constructor takes client's firstname, lastname and social security number. o The constructor should generate a random 6-digit number as the user account number. o The initial balance is 0 and the annual interest rate is fixed at 1.0% (0.01).o The withdraw method signature...
C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (name & ID), keeps track of a user's available balance. // It also keeps track of how many transactions (deposits and/or withdrawals) are made. public class BankAccount { Private String name private String id; private double balance; private int numTransactions; // Please define method definitions for Accessors and Mutator functions below Private member variables string getName(); // No set...
27. Suppose the unary ! operator is an overloaded member function of class String. For a String object s, which function call is generated by the compiler when it finds the expression Is? a. s.operator!0 b. s.operator!(default valuel, default value?,...) c. operator!(s d. A compiler error results because no arguments are given 28. Select the false statement regarding inheritance. a. A derived class can contain more attributes and behaviors than its base class b. A derived class can be the...
For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B() { super(); System.out.println(“B() called”);...
For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B() { super(); System.out.println(“B() called”); } public...
Find the syntax error(s) in the following class and function definition. [You need to identify the line number only). 1. class Class1 2.{ 3. private 4. int data; 5. public 6. class1: class 1(); 7. double function 1(); 8.} 9. class: class 10) 10.{ 11. data =5; 12.}
In Java. Please use the provided code Homework 5 Code: public class Hw05Source { public static void main(String[] args) { String[] equations ={"Divide 100.0 50.0", "Add 25.0 92.0", "Subtract 225.0 17.0", "Multiply 11.0 3.0"}; CalculateHelper helper= new CalculateHelper(); for (int i = 0;i { helper.process(equations[i]); helper.calculate(); System.out.println(helper); } } } //========================================== public class MathEquation { double leftValue; double rightValue; double result; char opCode='a'; private MathEquation(){ } public MathEquation(char opCode) { this(); this.opCode = opCode; } public MathEquation(char opCode,double leftVal,double rightValue){...
Please answer all the questions thank you 1) (Classes – 20 Points) Consider the following class declaration for Time to complete the questions below: DO NOT WRITE MORE THAN ASKED FOR. class Time private: int hours; int minutes; public: Time(); Time (int , int m = 0); void addMin(int m); void addHr(int h); void reset(int h = 0, int m = 0); Time operator+(const Time & t) const; Time operator-(const Time & t) const; Time operator*(double n) const; friend Time...