Code(in simple notepad and executed in command prompt:
class Product {//add public before class keyword
int stockNumber;
int price;
public int getStockNumber() {//getter for
stockknumber
return
stockNumber;
}
public void setStockNumber(int stockNumber)
{//setter for stocknumber
this.stockNumber =
stockNumber;//setting our object stocknumber to user given stock
number
}
public int getPrice() {//getter for
price
return price;
}
public void setPrice(int price) {//setter for
price
this.price =
price;
}
}//end of product class
class Book extends Product{//add public before class keyword
String author;
String title;
int numberPages;
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author =
author;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title =
title;
}
public int getNumberPages() {
return
numberPages;
}
public void setNumberPages(int numberPages)
{
this.numberPages =
numberPages;
}
}//end of class Book
public class demo{//add public before class keyword
public static void main(String[] args){
Book b1=new Book();//creating book object b1
b1.setStockNumber(35);//setting stockknumber to 35 price to 432
title to abstarct algebra and author to gilbert and number of pages
to 543 in this method and subsequent 4 calls
b1.setPrice(432);
b1.setTitle("abstract algebra");
b1.setAuthor("gilbert");
b1.setNumberPages(543);
System.out.println("stocknumer is = "+b1.getStockNumber());//using
gtters
System.out.println("price is = "+b1.getPrice());
System.out.println("authorname is = "+b1.getAuthor());
System.out.println("title is is = "+b1.getTitle() );
System.out.println("number of pages is is =
"+b1.getNumberPages());
}//end of main
}//end of demo class
Note:if your working in some ide please type public in
front of 3 classes and save 3 classes in 3 files
for ex save Product as Product.java
save Book as Book.java
save demo as demo.java
i worked in simple command prompt and created only one file and also food class was not needed in this code so i didnt code food class
Output in command prompt
Now create the Book class that inherits from Product. Don't forget that each class must go...
Create a class named Book that contains data fields for the title and number of pages. Include get and set methods for these fields. Next, create a subclass named Textbook, which contains an additional field that holds a grade level for the Textbook and additional methods to get and set the grade level field. Write an application that demonstrates using objects of each class. Save the files as Book.java, Textbook.java, and DemoBook.java.
You need to program a simple book library system. There are three java classes Book.java // book object class Library.java //library class A2.java //for testing The Book.java class represents book objects which contain the following fields title: a string which represents the book title. author: a string to hold the book author name year: book publication year isbn: a string of 10 numeric numbers. The book class will have also 3 constructors. -The default no argument constructor - A constructor...
Please use netBeans Exercise 4:A librarian needs to keep track of the books he has in his Library.1. Create a class Book that has the following attributes: ISBN, Title, Author, Subject, and Price. Choose anappropriate type for each attribute.2. Add a static member BookCount to the class Book and initialize it to zero.3. Add a default constructor for the class Book. Increment the BookCount static member variable and an initialization constructor for the class Book. Increment the BookCount in all constructors.4....
c ++ Create a class Book with the data members listed below. title, which is a string (initialize to empty string) sales, which is a floating point value (as a double, initialize to 0.0) Include the following member functions: Include a default constructor, a constructor with parameters for each data member (in the order given above), getters and setter methods for each data member named in camel-case. For example, if a class had a data...
MUST BE WRITTEN IN C++ Objective: Learn how to define structures and classes, create and access a vector of structures, use sort with different compare functions. Assignment: Your program will use the same input file, but you will print the whole book information, not just the title. And, most importantly, this time you will take an object oriented approach to this problem. Detailed specifications: Define a class named Collection, in which you will define a structure that can hold book...
MUST BE WRITTEN IN C++ Objective: Learn how to define structures and classes, create and access a vector of structures, use sort with different compare functions. Assignment: Your program will use the same input file, but you will print the whole book information, not just the title. And, most importantly, this time you will take an object oriented approach to this problem. Detailed specifications: Define a class named Collection, in which you will define a structure that can hold book...
JAVA Objective : • Learning how to write a simple class. • Learning how to use a prewritten class. • Understanding how object oriented design can aid program design by making it easier to incorporate independently designed pieces of code together into a single application. Instructions: • Create a project called Lab13 that contains three Java file called Book.java , Bookstore.java and TempleBookstore.java • I’ve provided a screenshot of how your project should look like. • Be sure to document...
Look at this partial class definition, and then answer questions a - b below: Class Book Private String title Private String author Private String publisher Private Integer copiesSold End Class Write a constructor for this class. The constructor should accept an argument for each of the fields. Write accessor and mutator methods for each field. Look at the following pseudocode class definitions: Class Plant Public Module message() Display "I'm a plant." End Module...
USING BLUEJ: You will write from scratch a class called Heater that represents an adjustable thermostat. Follow the detailed steps below. This is based on Exercises 2.93 - 2.94 (6e) / 2.92 - 2.93 (5e) in the book, but with slight modifications, so be sure to follow the instructions below. Create a new BlueJ project named LastName-heater using your last name. Create a class named Heater At the top of the source code for Heater, add documentation like this: /**...
I tried to complete a Java application that must include at a minimum: Three classes minimum At least one class must use inheritance At least one class must be abstract JavaFX front end – as you will see, JavaFX will allow you to create a GUI user interface. The User Interface must respond to events. If your application requires a data backend, you can choose to use a database or to use text files. Error handling - The application should...