Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
6th Edition
ISBN: 9780134477367
Author: David J. Barnes, Michael Kolling
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 11, Problem 13E
Program Plan Intro
To identify whether the given code will compile successfully or not.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
For the programming language Java
Create a class Animal Create a class Cat, and a class Dog, and a class Bearded Dragon which extend Animal. Add to your Animal class: Member: name Methods: Public Animal (String name) //constructor public void makes Sound () with the implementation printing out a generic animal sound. Next, override (add) the makes Sound() method to your Cat and Dog class, with the implementation specific to each animal (i.e, cat says purr..). Do not override the makesSound() for your Dragon (bearded dragons don't make sounds!) Note, you'll also need a constructor in each of your subclasses which calls super(name) to initialize the common 'name' member of Animal. Next (in your test harness) create a List of different Animals ( a couple cats, a dog, a dragon... ) and add these Animals to your list. Iterate through your list & call makeSound on each. (you should observe the makeSound method called will be: cat -> from Cat class, dog-> from Dog class, bearded Dragon -> from Animal class ) EC:…
Create a deck of cards class. Internally, the deck of cards should use another class, a card class. Your requirements are:
The Deck class should have a deal method to deal a single card from the deck
After a card is dealt, it is removed from the deck.
There should be a shuffle method which makes sure the deck of cards has all 52 cards and then rearranges them randomly.
The Card class should have a suit (Hearts, Diamonds, Clubs, Spades) and a value (A,2,3,4,5,6,7,8,9,10,J,Q,K)
Chapter 11 Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- In Java Write a class definition for a Rectangle class that contains:• Two int fields, length and width.• Mutator and accessor methods for the length and width fields.• A Boolean method named isSquare that returns true if the rectangle’s lengthand width are the same and false otherwise.b) Write a class definition for a RectangleDriver class that contains a main methodthat acts as a driver for the Rectangle class of the previous problem. The main methodshould do this:• Construct a Rectangle object named rect.• Use the mutator methods to assign arbitrary values to rect’s length and widthfields.• Use the Boolean method to determine if rect is a square.-- If rect is a square, print “Square: ” and then the square’s dimensions.For example: Square: 4x4.-- If rect is not a square, print “Rectangle: ” and then the rectangle’sdimensions. For example: Rectangle: 6x13.• In printing the above messages, use the accessor methods to retrieve therectangle’s dimensionsarrow_forwardpublic interface Rational { /** Determines whether this Rational object represents a value less than one. * @return true if this Rational is less than 1, false else public boolean islessThanOne (); } Write the class Goo that implements this interface. Goo must use an array. Your answer must include all necessary fields and any additional private methods as needed for your implementation. You may not use ArrayList, or any similar class.arrow_forwardJava Program The assignment requires two classes. Put all classes in the same package. Class Employee Attributes (all private): id: String lastName: String firstName: String salary: int Methods: Parameterized constructor for initializing a new Employee instance Getters for all attributes toString method to display an Employee's attributes (See output of executable below) Executable Class Create an array of at least eight Employee objects. Be sure to use many with identical last names, but don't order them by name in the array. Create an ArrayList from the array. Sort the ArrayList first by last name and then by first name. Using the forEach method and a lambda expression, print all employees alphabetically sorted by name. Create a LinkedList from the ArrayList. Create an iterator capable of cycling both forward and backward through the LinkedList. Iterate forward through the LinkedList without generating any output. Then iterate backwards through the LinkedList to print…arrow_forward
- Write the source code of the class Passenger. A passenger can travel with an infant (i.e. his/her child). Code the class Infant as an inner class of the class Passenger. If a passenger is not travelling with an infant, the getInfantMonths method must return –1.arrow_forwardConsider: class Automobile { } What happens if you try to run: ? new Automobile(); Nothing happens It does not run A new class is created A new object is createdarrow_forwardWrite a Java class Person for dealing with persons. Your class must have the following features: Person id: long name: String gender: String + Person() + Person (id: long, name: String, gender: String) + Create setter and getter for all data fields. + Override toString() method: you have to return required data Fields values. Constructor: public Person(): A default constructor, should initialize the data fields to their default values. public Person (SSN: long, name: String, gender: String): A constructor with parameters, that creates the person object by setting specified parameters. Instance methods: public void setName(name: String): Used to set the full name of the person. public void setGender(gender: String): Used to set the gender of the person. public long getId(): This method returns the id of the person. public String getGender(): This method returns the gender of the person. public String getName(): This method returns the full name of the person. public String…arrow_forward
- Exercise (Section 30/40): Implement a superclass Appointment and subclasses Onetime, Daily, and Monthly. An appointment has a description (for example, "see the dentist") and a date. Write a method occursOn(int year, int month, int day) that checks whether the appointment occurs on that date. For example, for a monthly appointment, you must check whether the day of the month matches. Then fill an array of Appointment objects with a mixture of appointments. Have the user enter a date and print out all appointments that occur on that date. Give the user the option to add new appointments. The user must specify the type of the appointment, the description, and the date.arrow_forwardSuppose that we have created a class called Car by which we have created the objects below: Car herCar = new Car();Car hisCar = new Car(); Car myCar = hisCar;hisCar = null;myCar = herCar;herCar = hisCar; You may find it easier to solve this problem if you use memory model.arrow_forwardWrite a class Student with the following attributes (make sure the attributes are private using name mangling): name: String id : Integer courses: List of Strings grades: List of Integers The class must include the following operations: A constructor that receives as input the name and id. Getters for each attribute. add_course(course: String, grade: Integer) : Bool -- This operation adds the course name to the list of courses and the grade to the list of grades. The method must confirm before adding that the course is a String and the grade is an Integer, otherwise the operation won't be performed. The method must return True if the course and grades were added, False otherwise. __str__() -- Should return the following information "Student name: <name> -- Courses passed: <number of courses passed>". Courses passed means courses with a grade equal to 60 or larger. Check the testcase for details. pass_ratio(): Float -- Returns the pass ratio as a percentage of…arrow_forward
- Implement the following parking permit class using java It has a dependency on the car class, no need to implement the car class. Use the diagram for refrencearrow_forwardWhen a method in a subclass overrides a method in superclass, it is still possible to call the overridden method using super keyword. If you write super.func() to call the function func(), it will call the method that was defined in the superclass. You are given a partially completed code in the editor. Modify the code so that the code prints the following text: Hello I am a motorcycle, I am a cycle with an engine. My ancestor is a cycle who is a vehicle with pedals. import java.util.*;import java.io.*; class BiCycle{String define_me(){return "a vehicle with pedals.";}} class MotorCycle extends BiCycle{String define_me(){return "a cycle with an engine.";}MotorCycle(){System.out.println("Hello I am a motorcycle, I am "+ define_me()); //////code hereString temp=define_me(); //Fix this line and code here/////code ends here System.out.println("My ancestor is a cycle who is "+ temp );}}class Solution{public static void main(String []args){MotorCycle M=new MotorCycle();}}arrow_forwardWhat is the purpose of a constructor? It creates an array of data values associated with an object. It prints all of the information about our object. It returns all data members from an object back to the main method. It allows us to set our own default values when we create an object. in javaarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Memory Management Tutorial in Java | Java Stack vs Heap | Java Training | Edureka; Author: edureka!;https://www.youtube.com/watch?v=fM8yj93X80s;License: Standard YouTube License, CC-BY