Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class HogwartsHouse { public HogwartsHouse() { name = null; housePoints = 0; } public HogwartsHouse(String name, int housePoints) { this.name = name; this.housePoints =

public class HogwartsHouse { public HogwartsHouse() { name = null; housePoints = 0; } public HogwartsHouse(String name, int housePoints) { this.name = name; this.housePoints = housePoints; } public void setName(String name) { this.name = name; } public void addPoints(int newPoints) { housePoints += newPoints; } public void movePointsTo(HogwartsHouse house) { house.housePoints += 10; this.housePoints -= 10; } public void stealAllPoints(int housePoints) { this.housePoints += housePoints; housePoints = 0; } public int getPoints() { return housePoints; } public String getHouseInfo() { return name + ": " + housePoints; } private String name; private int housePoints; }
public class MainClass { public static void resetHouse(HogwartsHouse house) { house = new HogwartsHouse(); } public static void main(String args[]) { HogwartsHouse gryffindor = new HogwartsHouse("Gryffindor", 0); HogwartsHouse hufflepuff = new HogwartsHouse("Hufflepuff", 0); HogwartsHouse slytherin = new HogwartsHouse("Slytherin", 0); HogwartsHouse ravenclaw = new HogwartsHouse(); ravenclaw.addPoints(25); gryffindor.addPoints(50); hufflepuff.addPoints(10); slytherin.stealAllPoints(ravenclaw.getPoints()); System.out.println(ravenclaw.getHouseInfo()); // 1 System.out.println(slytherin.getHouseInfo()); // 2 System.out.println(); gryffindor.movePointsTo(hufflepuff); System.out.println(gryffindor.getHouseInfo()); // 3 System.out.println(hufflepuff.getHouseInfo()); // 4 System.out.println(); resetHouse(slytherin); System.out.println(slytherin.getHouseInfo()); // 5 } }

What is printed by the lines with comments labeled 1, 2, 3, 4, and 5?

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

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

Cite the reasons employees join unions.

Answered: 1 week ago