i programs i did for a recent assignment:
it was written in java (my first and only language for now lol )
the program has a instant data and a driver, the instant data tells the properties of the object called books
books hold three items, the title, the authers name and the publisher
i also added the +++++++++++++++++++ line to separate the three authers ^_^
also i have a string that says "hello" ^_^
it was written in java (my first and only language for now lol )
the program has a instant data and a driver, the instant data tells the properties of the object called books
books hold three items, the title, the authers name and the publisher
i also added the +++++++++++++++++++ line to separate the three authers ^_^
also i have a string that says "hello" ^_^
Code:
/*
* BookShelf.java
*
* Created on November 21, 2007, 9:10 AM
*
* donald mckenney 13033225
*
*/
public class BookShelf {
/** Creates a new instance of BookShelf */
public BookShelf() {
}
public static void main(String[] args) {
Books book1 = new Books("Java Software Solutions", "Lewis",
"Addison Wesley");
Books book2 = new Books("Worlds of Amano", "Amano",
"DH Press");
Books book3 = new Books("A Gift of Fire", "Baase",
"Prentice Hall");
System.out.println("Book Title: " + book1.title() +
"\n Author: " + book1.author() +
"\n Publisher: " + book1.publisher());
System.out.println("++++++++++++++++++++++++++");
System.out.println("Book Title: " + book2.title() +
"\n Author: " + book2.author() +
"\n Publisher: " + book2.publisher());
System.out.println("++++++++++++++++++++++++++");
System.out.println("Book Title: " + book3.title() +
"\n Author: " + book3.author() +
"\n Publisher: " + book3.publisher());
}
}
Code:
/*
* Books.java
*
* Created on November 21, 2007, 9:10 AM
*
* donald mckenney 13033225
*
*/
public class Books {
/** Creates a new instance of Book */
public Books() {
}
private String title;
private String author;
private String publisher;
public Books (String newTitle, String newAuthor, String newPublisher){
title = newTitle;
author = newAuthor;
publisher = newPublisher;
}
//getter method to return the value of title
public String getTitle(){
return title;
}
//setter method to set a new value to title
public void setTitle(String newTitle){
title = newTitle;
}
//getter method to return the value of author
public String getAuthor(){
return author;
}
//setter method to set a new value to author
public void setAuthor(String newAuthor){
author = newAuthor;
}
//getter method to return the value of publisher
public String getPublisher(){
return publisher;
}
//setter method to set a new value to publisher
public void setPublisher(String newPublisher){
publisher = newPublisher;
}
//toString method is to be used when we use println method with a object
public String toString(){
return("Book title: " + title +
"\nAuthor: " + author +
"\nPublisher: " + publisher);
}
public String title(){
return title;
}
public String author(){
return author;
}
public String publisher(){
return publisher;
}
}
Last edited: