Question: Given the following class: public class CashRegister {// in file CashRegister.java private int itemCount; private double totalPrice; // constructor omitted public void clear() { totalPrice

 Given the following class: public class CashRegister {// in file CashRegister.javaprivate int itemCount; private double totalPrice; // constructor omitted public void clear(){ totalPrice =0;} public void addItem(double price) { totalPrice += price; }

Given the following class: public class CashRegister {// in file CashRegister.java private int itemCount; private double totalPrice; // constructor omitted public void clear() { totalPrice =0;} public void addItem(double price) { totalPrice += price; } Select the answer that best describes any issues with code snippet shown below. // in another file (Tester. java) CashRegister register2 = new CashRegister(); register2.clear(); register2.addItem(0.95); System.out.println(register2.totalPrice); the constructor for the register does not take any parameters the this keyword needs to be used to access totalPrice there is no problem with the code shown totalPrice is a private field and cannot be accessed outside the class the clear method is called before the addltem method Consider the class below: public class Goblin \{ private int snacksEaten =0; private String name; private Arraylist favMeals; // favorite meals public Goblin(String name) \{ this. favMeals = new ArrayList (); this.name = name; public String getName() { return name; } public void setName(String n){ this.name =n;} public ArrayList getFavoriteMeals() { return favMeals; } public void eatSnack() { snacksEaten++; } public void addFavoriteMeal(String mealName) { favMeals.add(mealName); } Select the option that lists all mutator methods. getFavoriteMeals(), getName(), setName(..) addFavoriteMeal(..), getFavoriteMeals(), setName(..) addFavoriteMeal(..), eatSnack(), setName(..) getFavoriteMeals(), eatSnack(), setName(..) Consider the following CashRegister class: public class CashRegister \{ int itemCount; double totalPrice; public CashRegister() \{ this.itemCount =0; this.totalPrice =0.0; public void addItem(double itemPrice) \{ this.itemCount = this. itemCount +1; this.totalPrice = this.totalPrice + itemPrice; \} ? Now consider the following client/user code involving CashRegister objects (line numbers on the left): 1 CashRegister reg1 = new CashRegister(); 2 CashRegister reg2 = reg 1; 3 reg2.addItem(2.95); What is the and for after line 3 executes? Select all answers that are true after line 3. reg1.itemCount==1andreg1.totalPrice==2.95 reg1 .itemCount == reg 2 .itemCount and reg1.totalPrice == reg2.totalPrice reg1. itemCount ==1 and reg 1. totalPrice ==3.0 reg1. .temCount ==0 and reg1.totalPrice ==0.0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!