Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The program must meet the following criteria: Switch from a sequential console-o

ID: 3702233 • Letter: T

Question

The program must meet the following criteria:

Switch from a sequential console-oriented approach to an event driven graphical application that performs all the same tasks. You may create the interfaces within a browser window (via JSF, JSP, or servlets) or as a JavaFX application.

Present the user with the options to:

1. Add a pet (Pet name, Food Cost, Vet Cost)

2. Display Pets

3. Display Avg Costs (Food & Vet)

4. Exit the application (using an approach appropriate to the interface being used)

Contain a minimum of 3 pets.

This includes object inheritance.

The application should be visually appealing and with a logical, easy to follow layout.

Explanation / Answer

<h:panelGrid columns="2">

<h:outputText id="addpetheading" value="Add Pet "/></h:outputText >

<h:outputText id="petname" value="Enter Pet Name :" />

<h:inputText value="#{petBean.petname}/>

<h:outputText id="foodcost" value="Enter food cost:" />

<h:inputText value="#{petBean.petfood} />

<h:outputText id =" vetcost" value="Enter vet cost" />

<h:inputText value ="#{petBean.vet}"/>

<a4j:commandButton value="ADD" action ="#{petBean. add} reRendered="displaypetinfo" />

</h:panelGrid>

<h:dataTable id=" displaypetinfo" value="#{petBean}" >

<h:column >

<f:facet name="header" >Pet name </f:facet>

<h:outputText value="#{petBean. petname } "/>

</h:column >

<h:column >

<f:facet name ="header" >Food cost</f:facet>

#{petBean.petFood}

</h:column >

<h:column >

<f:facet name ="header" >Vet</f:facet>

#{petBean.vet}

</h:column >

</h:dataTable>

</body>

//java code to excecute when clicked on add

Class PetBean{

private String petname ;

private String petfood;

private String vet;

private List<Object[] > petList= new ArrayList <Object [] >() ;

public String getPetname(){
return petname ;}

public String setPetname(String petname ){
return petname=this.petname ;
}


public String getPetfood(){
return petfood ;}

public String setPetfood(String petfood ){
return petfood=this.petfood ;
}

public String getVet(){
return vet ;}

public String setVet(String vet ){
return vet=this.vet ;
}

public void add() {

static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://localhost/STUDENTS";
     // Database credentials
    static final String USER = "username";
     static final String PASS = "password";
     
        Connection conn = null;
         Statement stmt = null;
         try{ //STEP 2: Register JDBC driver
         Class.forName("com.mysql.jdbc.Driver");
         //STEP 3: Open a connection
         System.out.println("Connecting to a selected database...");
         conn = DriverManager.getConnection(DB_URL, USER, PASS);
         System.out.println("Connected database successfully...");
         //STEP 4: Execute a query
          System.out.println("Creating statement...");
          stmt = conn.createStatement();
          String sql = "insert into petTablename (name, food, vet) values(petname,petfood vet) ;
           stmt.executeUpdate(sql);
} catch(Exception e) {e.printStrackTrace();}

}


public String getPetList(){

//JDBC driver name and database URL
    static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
    static final String DB_URL = "jdbc:mysql://localhost/STUDENTS";
     // Database credentials
    static final String USER = "username";
     static final String PASS = "password";
      public static void main(String[] args) {
        Connection conn = null;
         Statement stmt = null;
         try{ //STEP 2: Register JDBC driver
         Class.forName("com.mysql.jdbc.Driver");
         //STEP 3: Open a connection
         System.out.println("Connecting to a selected database...");
         conn = DriverManager.getConnection(DB_URL, USER, PASS);
         System.out.println("Connected database successfully...");
         //STEP 4: Execute a query
          System.out.println("Creating statement...");
          stmt = conn.createStatement();
         String sql="select name, food, vet from petTable ";
    ResultSet rs = stmt.executeQuery(sql);
     //STEP 5: Extract data from result set

Pet p=new pet() ;
     while(rs.next()){
     // //Retrieve by column name
     p.setPetname(rs.getString("name"));
     p. setFood(rs.getString("food"));
      p. setVet(rs.getString("vet"));

petList. add(p) ;}
    

return petList ;}

public String setPetList(String petList ){
return petList=this.petList ;
}

}