Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions

Question

5. Have you stressed the topics relevance to your audience?

Answered: 1 week ago