Concept explainers
A) class Circle:
{
private
double centerX;
double centerY;
double radius ;
public
setCenter(double, double) ;
setRadius(double };
}
B) Class Moon;
{
Private;
double earthWeight;
double moonWeight;
Public;
moonWeight (double ew);// Constructor
{ earthWeight = ew; moonWeight = earthWeight / 6; }
double getMoonWeight ();
{ return moonWeight; }
}
int main()
{
double earth ;
cout >> "What is your weight?"·
cin << earth;
Moon lunar(earth );
cout << "On the moon you would weigh"
<<lunar.getMoonWeight() << end l ;
return 0;
}
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Starting Out with C++: Early Objects (9th Edition)
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Starting Out With Visual Basic (8th Edition)
Modern Database Management
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Degarmo's Materials And Processes In Manufacturing
- class Lease{ private String name; private int aptNumber; private double rent; private int term; private static final int FEE = 10; public Lease(){ name = "XXX"; aptNumber = 0; rent = 1000; term = 12; } public void setName(String tenant) { name = tenant; } public void setAptNumber(int apt){ aptNumber = apt; } public void setRent(double monthRent) { rent = monthRent; } public void setTerm(int t){ term = t; } public String getName(){ return name; } public int getAptNumber(){ return aptNumber; } public double getRent(){ return rent; } public int getTerm(){ return term; } public void addPetFee(){ rent = rent + FEE; } } Create a class named TestLease as instructed below: Instantiate four Lease objects in the main()method. Change the aptNumber value for the first object to 20 Change the rent value…arrow_forward49. Consider the following class definition. public class Cylinder } private double baseRadius; private double height; public Cylinder () baseRadius = 0; height = 0; public Cylinder (double 1, double h) } baseRadius - 1; height = h; { public void set (double r, double h) } baseRadius = r; height = h; { public String toString () } return (baseRadius + It n + height); { public double SurfaceArea () return 2 * 3.14 * baseRadius height; public double volume () } return 3.14 baseRadius * baseRadius * height; { Which of the following statements correctly instantiates the Cylinder object myCylinder? (i) Cylinder mycylinder = new Cylinder (2.5, 7.3) : (ii) class Cylinder myCylinder = new Cylinder (2.5, 7.3); (ii) myCylinder new Cylinder (2.5, 7.3); %3D a. Only (i) b. Only (i) c. Only (iüi) d. Both (ii) and (ii)arrow_forwardpackage myq2; class Sale { int sellerID, milksale, buttersale; Sale(int sid, int ms, int bs) { sellerID = sid; milksale- ms; buttersale - bs; } elling dairy ifferent days using OOP ers, based on YQ2 int totalsaving(){ return milksale + buttersale; } } ale public class Myq2 { public static void main(String[] args) { Sale s = new Sale(111, 10, 20); System.out.println("Seller ID" + s.sellerID ); System.out.println("Total Saving "+s.totalsaving()); } } 4) Use the parameterized constructor to initialize the member variables of the class. 5) Display the following details of seller using object of Sale class. seller ID, totalsaving Solution to programarrow_forward
- public class FoodItem { private String name; private double fat; private double carbs; private double protein; // TODO: Define default constructor // TODO: Define second constructor with parameters to initialize private fields (name, fat, carbs, protein) public String getName() { return name; } public double getFat() { return fat; } public double getCarbs() { return carbs; } public double getProtein() { return protein; } public double getCalories(double numServings) { // Calorie formula double calories = ((fat * 9) + (carbs * 4) + (protein * 4)) * numServings; return calories; } public void printInfo() { System.out.println("Nutritional information per serving of " + name + ":"); System.out.printf(" Fat: %.2f g\n", fat); System.out.printf(" Carbohydrates: %.2f g\n", carbs); System.out.printf(" Protein: %.2f g\n", protein); }} import java.util.Scanner; public class NutritionalInfo {…arrow_forwardpublic class Plant { protected String plantName; protected String plantCost; public void setPlantName(String userPlantName) { plantName = userPlantName; } public String getPlantName() { return plantName; } public void setPlantCost(String userPlantCost) { plantCost = userPlantCost; } public String getPlantCost() { return plantCost; } public void printInfo() { System.out.println(" Plant name: " + plantName); System.out.println(" Cost: " + plantCost); }} public class Flower extends Plant { private boolean isAnnual; private String colorOfFlowers; public void setPlantType(boolean userIsAnnual) { isAnnual = userIsAnnual; } public boolean getPlantType(){ return isAnnual; } public void setColorOfFlowers(String userColorOfFlowers) { colorOfFlowers = userColorOfFlowers; } public String getColorOfFlowers(){ return colorOfFlowers; } @Override public void printInfo(){…arrow_forwardEach of the following class declarations or programs contain errors. Find as many as possible. 73. class Circle: { private double centerX; double centerY; double radius; public setCenter(double, double); setRadius(double); } 74. #include using namespace std; Class Moon; { Private; double earthWeight; double moonWeight; Public; moonWeight(double ew); { earthWeight = ew; moonWeight = earthWeight / 6; } double getMoonWeight(); { return moonWeight; } }arrow_forward
- class Base { public: int x, y: public: Base(int i, int j) { x = i; y = j; }}; class Derived : public Base public: Derived (int i, int j) { x = i; y = j; void display() {cout « x <<" "<< y; }}; int main(void) { Derived d(5, 5); d.display(); return e; Error O X=5,Y=5 X-0,Y=0 None of the above Other:arrow_forwardclass IndexItem { public: virtual int count() = 0; virtual void display()= 0; };class Book : public IndexItem { private: string title; string author; public: Book(string title, string author): title(title), author(author){} virtual int count(){ return 1; } virtual void display(){ /* YOU DO NOT NEED TO IMPLEMENT THIS FUNCTION */ } };class Category: public IndexItem { private: /* fill in the private member variables for the Category class below */ ? int count; public: Category(string name, string code): name(name), code(code){} /* Implement the count function below. Consider the use of the function as depicted in main() */ ? /* Implement the add function which fills the category with contents below. Consider the use of the function as depicted in main() */ ? virtualvoiddisplay(){ /* YOU DO NOT NEED TO IMPLEMENT THIS FUNCTION */ } };arrow_forwardQUESTION 15 public class numClass { private int a; private static int y = 10; public numClass(int newX) {a=newx; } public void set(int newx) { a=newx; y+=a; } public void setY(int newy) { y=newY; } public static int getY() { return y; } }// end of class public class output { public static void main(String[] args) { numClass one = new numClass(10); numClass two = new numClass (2); try{ one. sety(30); two.set(4); if(one.getY()==30) throw new Exception ("30"); one.setY(40); } catch (Exception e) { two.sety (50); } System.out.println(two.getY()); }// end of main } // end of classarrow_forward
- Instrument.java public class Instrument { protectedStringinstrumentName; protectedStringinstrumentManufacturer; protectedintyearBuilt, cost; publicvoidsetName(StringuserName) { instrumentName = userName; } publicStringgetName() { return instrumentName; } publicvoidsetManufacturer(StringuserManufacturer) { instrumentManufacturer = userManufacturer; } publicStringgetManufacturer(){ return instrumentManufacturer; } publicvoidsetYearBuilt(intuserYearBuilt) { yearBuilt = userYearBuilt; } publicintgetYearBuilt() { return yearBuilt; } publicvoidsetCost(intuserCost) { cost = userCost; } publicintgetCost() { return cost; } publicvoidprintInfo() { System.out.println("Instrument Information: "); System.out.println(" Name: " + instrumentName); System.out.println(" Manufacturer: " + instrumentManufacturer); System.out.println(" Year built: " + yearBuilt); System.out.println(" Cost: " + cost); } } StringInstrument.java // TODO: Define a class: StringInstrument that is derived from…arrow_forward8. OOPS Theory #6 public class Car { public void horn() { System.out.println("Horn horn"); } } public class Ferrari extends Car { public void horn() { System.out.println("Ferarriiiiii"); } } public static void main(String[] args) { Ferrari ferrari = new Car(); ferrari.horn(); } Pick ONE option Horn horn Ferarriiii Cannot compile Runtime exception Clear Selection 9. OOPS Theory #7 In Java, we can achieve the abstraction by creating the blueprint of an object and only have abstract methods. What do we call this? Pick ONE option Interface Encapsulation Instance Protected Clear Selectionarrow_forwardpublic class Player { private int jerseyNumber; private int rating; public Player(int jerseyNumber, int rating) { this.jerseyNumber = jerseyNumber; this.rating = rating; } public int getJerseyNumber() { return jerseyNumber; } public void setJerseyNumber(int jerseyNumber) { this.jerseyNumber = jerseyNumber; } public int getRating() { return rating; } public void setRating(int rating) { this.rating = rating; } @Override public String toString() { return "Jersey number: " + jerseyNumber + ", Rating: " + rating; }}public class RosterManager { private ArrayList<Player> roster; public RosterManager() { roster = new ArrayList<>(); } public void addPlayer(Player player) { roster.add(player); } public void updatePlayerRating(int jerseyNumber, int newRating) { for (Player player : roster) { if (player.getJerseyNumber() ==…arrow_forward
- 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