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

(Graph Representations) For each application below, state whether an adjacency l

ID: 3592054 • Letter: #

Question

(Graph Representations) For each application below, state whether an adjacency list or an adjacency matrix is the better representation for the graph. Then use 1-2 sentences to explain why. (Flight Networks) Model Data: Airports (about a hundred of them), their lo- catins, and for each airport , a list of other airports that Inay be flown to from A with a non-stop flight. Objective: Use graph theory to design an algorithm that, when given a sequence of airports, determines if there are non-stop flights from one airport to the next for the entire sequence. (Communication Networks) Model Data: Routers that connect computers to- gether in a communication network, and for cach router R, a list of computers and routers that R may forward a packet to. Objective: Use graph thcory to design an algorithm that, given a source computer, for each other computer (call this the target computer, finds the minimum number of routers required to forward a packet from the source computer to the target computer (Social Networks) Model Data: User accounts, and for cach user U, a list of other users that are friends with U. The size of the network is comparable to the size of Facebook's social network. Objective: Use graph thecory to design an algorithm that determines if user A is friends with user B as quickly as possible.

Explanation / Answer

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.JOptionPane;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*
*/
public class Account {
  

private int AcctNo, Cid;
private double Balance;
private String Type;

public int getAcctNo() {
return AcctNo;
}

public void setAcctNo(int AcctNo) {
this.AcctNo = AcctNo;
}

public int getCid() {
return Cid;
}

public void setCid(int Cid) {
this.Cid = Cid;
}

public double getBalance() {
return Balance;
}

public void setBalance(double Balance) {
this.Balance = Balance;
}

public String getType() {
return Type;
}

public void setType(String Type) {
this.Type = Type;
}

public void selectDB(int acctNo) {
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection conn = DriverManager.getConnection("jdbc:ucanaccess://D:ChattBankMDB.mdb");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("Select * from Accounts where AcctNo = " + acctNo);
while (rs.next()) {
setAcctNo(rs.getInt(1));
setCid(rs.getInt(2));
setType(rs.getString(3));
setBalance(rs.getDouble(4));
}
  

} catch (Exception e) {
System.out.println(e.getMessage());
}

}

public void deposit(double amt) {
setBalance(getBalance() + amt);
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://D:ChattBankMDB.mdb");
Statement stmt = con.createStatement();
stmt.executeUpdate("update Accounts set [Balance] ="+getBalance()+" where [AcctNo] = "+getAcctNo());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
  
public void withdraw (double amt) {
setBalance(getBalance() - amt);
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
Connection con = DriverManager.getConnection("jdbc:ucanaccess://D:ChattBankMDB.mdb");
Statement stmt = con.createStatement();
stmt.executeUpdate("update Accounts set [Balance] ="+getBalance()+" where [AcctNo] = "+getAcctNo());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public void display(){
JOptionPane.showMessageDialog(null,"Balance = "+getBalance());


}