Programming

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" ^_^

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:
^ thank you guru sir ^_^

that was my second... third one with a driver and an instants data ^_^

the first one was about a circle and its radius, (in a lab) and then i had to do this one and another on my own, we also added more data to the circle one to alot it to work with a rectangle too ^_^

right now im messing around with print outs

i know that the receipts i get from the dinning hall are im pretty sure printed out in java, it isnt a complex print-out and im sure i could re-produce it (and thats what im doing lol

but my wont be as much as there :frowning:

that program printout out this:
Code:
Main Dining Hall
211 xxx xxxx xxxx
Beaumont, TX 77710
000 000 0000
Cashier: xxxx xxxxxx



MCKENNEY, DONALD ******25
Date: 11/272007  Line number: 1
Order Number: 641

01:33:03 PM (2) Transaction 824
1 Lunch                    $5.95
                   Total:  $5.95
*********************************
Total Paid With Meal Acct   -1 CR
*********************************


Meal Acct remaining           12
Decline Acct Balance     $187.21
 
Last edited:
^ thank you sir guru

it will have to wait lol

LAN PARTY TOMORROW!! YES!!

and for sure i will be getting some *cough*free*cough* games via LAN :smile:
 
gui!

i made one yesterday and i have a week to finish the assigned one

mine: (well everyone's in there did the same Labs are fun lol)
Code:
//********************************************************************
//  EvenOdd.java       Java Foundations
//
//  Demonstrates the use of the JOptionPane class.
//
//      Donald Mckenney     13033225
//
//********************************************************************

import javax.swing.JOptionPane;

class EvenOdd
{
   //-----------------------------------------------------------------
   //  Determines if the value input by the user is even or odd.
   //  Uses multiple dialog boxes for user interaction.
   //-----------------------------------------------------------------
   public static void main (String[] args)
   {
      String numStr, result;
      int num, num2, num3, again;

      do 
      {
         numStr = JOptionPane.showInputDialog ("Enter an integer: ");

         num = Integer.parseInt(numStr);
         
         result = "That number is " + ((num%2 == 0) ? "even" : "odd");
         
         JOptionPane.showMessageDialog (null, result);
         
         numStr = JOptionPane.showInputDialog ("Enter another integer: ");
         
         num2 = Integer.parseInt(numStr);
         
         result = "The number is " + (num + num2);
         
         result = "The square root of " + (num + num2) + " is " + Math.sqrt(num + num2);
         
         JOptionPane.showMessageDialog (null, result);

         again = JOptionPane.showConfirmDialog (null, "Try Another?");
      }
      while (again == JOptionPane.YES_OPTION);
   }
}
 
Back
Top