I want the sample source code of Java, which uses a real world object to demonstrate the use of 'static' keyword. I am waiting

Showing Answers 1 - 1 of 1 Answers

debabrat panda

  • Sep 25th, 2006
 

i give you the pice of code whiich is used to display the shopping cart

BookCatalog.java

import java.util.*;
import dunu.UtilityClass;

public class BookCatalog {
 static UtilityClass us = null;
 
 public static Map book;
 
 static{
  us=new UtilityClass();
  String s= us.getApplicationProperties("PropertyValue");
  book=new HashMap();
  
  book.put("001",new ItemVO("01","Traditional Nursery Songs of England","Edited by Felix Summerly (Joseph Cundall, 1843) 1210.e.23 15.5x22 cm ",s,567));
  book.put("002",new ItemVO("02","Treasure Island","R. L. Stevenson (Cassell, 1883) C.71.c.18 19x11 cm",s,1389));
  book.put("003",new ItemVO("03","Peeps into Fariyland","(E. Nister; E. P. Dutton, 1896) Nister h.52 27.5x34.5 cm ",s,667));
 }
 public Collection getAllItems(){
  return book.values();
 }
 public boolean containsItem(String bookCode){
  return book.containsKey(bookCode);
 }
 public ItemVO getItem(String bookCode){
  return (ItemVO) book.get(bookCode);
  
 }
 
 
}

ItemVO.java

import java.math.BigDecimal;
import dunu.BookCatalog;


public class ItemVO {
 private String code;
 private String name;
 private String decsription;
 private String image;
 private double price;
 

 public ItemVO(String code, String name, String decsription, String image, double price) {
  
  this.code = code;
  this.name = name;
  this.decsription = decsription;
  this.image = image;
  this.price = price;
 }
 public String getCode() {
  return code;
 }
 public String getDecsription() {
  return decsription;
 }
 public String getImage() {
  return image;
 }
 public String getName() {
  return name;
 }
 public double getPrice() {
  return price;
 }
 public String getFormatedPrice(){
  return "$"+new BigDecimal(price).movePointLeft(2);
 }
 
 public boolean equals(Object o) {
     if (this == o) return true;
     if (this == null) return false;
     if (!(o instanceof ItemVO)) return false;
     return ((ItemVO)o).getCode().equals(this.code);
   }
 

}

book.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@page language="java"%>
<%@page import="dunu.*"%>
<%@ page import="java.util.*" %>

<HTML>
<HEAD>
<TITLE>Online Books</TITLE>

</HEAD>

<BODY bgcolor="#eeeeee">
<marquee bgcolor="#EG5408" loop="-1"><font color="#FFF000" face="bold" style="verdana" size="3">Book Shopping</font></marquee>
  <CENTER>
   <TABLE  width="90%">
    <TR>
     <TD>
      <TABLE>
       <TR>
        <TD><A HREF="C:/Tomcat/webapps/ShoppingCart/pages/aboutus.html"><font color="#egh876">About Us</font></A></TD>
       </TR>
       <TR>
        <TD><A HREF="#"><font color="#egh876">Books</font></A></TD>
       </TR>
       <TR>
        <TD><A HREF="C:/Tomcat/webapps/ShoppingCart/pages/search.html"><font color="#egh876">Search</font></A></TD>
       </TR>
       <TR>
        <TD><A HREF="C:/Tomcat/webapps/ShoppingCart/pages/cart.html"><font color="#egh876">Cart</font></A></TD>
       </TR>
       <TR>
        <TD><A HREF="C:/Tomcat/webapps/ShoppingCart/pages/login.html"><font color="#egh876">Login</font></A></TD>
       </TR>
      </TABLE>
     </TD>
    <td></td><td></td>
    <TD width="90%">
     </br>
      <CENTER><b><font face="Arial, Helvetica, sans-serif">You can see books by categories.</font></b></CENTER>
      </br>
      <table>
      <tr><td><font color="orange" size="4" face="Arial, Helvetica, sans-serif">Childern's Books</font></td></tr>
      </br>
      <tbody>
      <%
       for(Iterator I=new BookCatalog().getAllItems().iterator();I.hasNext();){
       ItemVO item=(ItemVO)I.next();
      %>
      <tr><td><font color="green" size="2" face="Arial, Helvetica, sans-serif">1.<%=item.getName()%></font></td>
      
      <th><%=item.getDecsription()%></th>
      <th>Price :- <%=item.getFormatedPrice()%></th>

      <td><A HREF="#"><IMG SRC="<%=item.getImage()%>" WIDTH="58" HEIGHT="65" BORDER="0" ALT=""></A></td>
      <TD><INPUT TYPE="submit" name="<%=item.getCode()%>" VALUE="Add to cart"></TD></TR>

      
      <%}%>
      </tbody>
      </table>
      
           
    </TD>
       
    
    </TR>
    
   </TABLE>
   
   </br>
   </br>
   </br>
   </br>
   </br>
   </br>
   </br>
   </br>
   </br>

   <TABLE align="right">
   <TR>
     <TD>
      &copy;copyright reserved by <IMG SRC="../images/dot_b.gif" WIDTH="5" HEIGHT="5" BORDER="0" ALT=""><b><a href="mailto:panda.1078@hotmail.com">&nbsp;Debabrat Panda</a></b>
     </TD>
    </TR>
   </TABLE>
  </CENTER>

</BODY>
</HTML>

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions