Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Sushi { private double price; private String sushiName; private int orderNumber; public Sushi () { } public Sushi ( int orderNumber, double price,

public class Sushi { private double price; private String sushiName; private int orderNumber; public Sushi() { } public Sushi(int orderNumber, double price, String sushiName) { super(); this.orderNumber = orderNumber; this.price = price; this.sushiName = sushiName; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public String getName() { return sushiName; } public void setName(String sushiName) { this.sushiName = sushiName; } public int getOrder() { return orderNumber; } public void setOrder(int orderNumber) { this.orderNumber = orderNumber; } public void display() { System.out.println("Sushi Price: $" + price ); System.out.println("Sushi Name: " + sushiName); System.out.println("Order Number: " + orderNumber); } }

---

public class Demo { public static void main(String[] args) { Sushi p1 = new Sushi(); p1.setPrice(10.5); p1.setName("Salmon"); p1.setOrder(1); p1.display(); Sushi p2 = new Sushi(2, 12.50, "Tuna"); p2.display(); } }

---------

1. Add a new method to your class called print()

The print() method is similar to the display method, but it will print the data to a file called "mydata.txt" rather then to the screen [1 point]

The file should append new data every time the print() method is called, and not replace it [1 point]

2. Create a subclass

Create a sub class that inherits everything from your base class. (For example, if Car is the base class then SportsCar could be your sub class) [1 point]

Provide at least one additional attribute to your subclass [1 point]

Create gettter/setter methods for it.

Create a default constructor for the subclass, that uses super to call the base class default constructor. [1 point]

It should set all attributes in the subclass as well as the super class to default values

Create a parameterized constructor for the subclass, that uses keyword super to pass the inherited parameters to the base class. [1 point]

It should set all attributes in the subclass as well as the super class to the values that are passed in to the constructor.

Override the print() method to print out (to the file "mydata.txt") all the instance variable values from the base class, and also from the sub class. [1 point]

3. Update main method

In your main method, create 2 new object using your subclass [1 point] Create one object using the no-arg (default) constructor of your sub-class.

Call the set methods to set all attribute data associated to that object.

Create one object using the parameterized constructor of your sub-class.

Create an ArrayList containing these 2 objects, and also the 2 objects from your BA5 assignment to have at least 4 total objects inside it. [1 point]

Loop through the ArrayList using a for loop and call the print() method for each object. [1 point]

Extra Credit (+1 point): Create a Java Interface (see Chapter 12) called Displayable that declares the display() and print() methods. Both your class and subclass should implement the interface.

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

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

4. I can tell when team members dont mean what they say.

Answered: 1 week ago