Question

Please help with this assignment For this assignment, you must design and develop a program to...

Please help with this assignment

For this assignment, you must design and develop a program to read any CSV file and output an HTML table. The program should be able to input any csv file with any number of fields and use the field headings in the CSV file's first row to become the table headings of the table. The program should output an HTML Bootstrap table with table headings and alternating zebra strips for rows. Your program should demonstrate the use of classes, objects, static, class scopes (private, public, protected). Your program is REQUIRED to use OOP programming techniques and demonstrate the DRY programming concept. Your program must use static and object (properties and methods) properly. Remember that objects are things and statics are actions. You can think of objects as the subject of a sentence and the static methods as the verbs.  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program for converting CSV file into HTML table

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.io.PrintStream;

class CsvToHtml {

public static String escapeChars(String lineIn) {
StringBuilder sb = new StringBuilder();
int lineLength = lineIn.length();
for (int i = 0; i < lineLength; i++) {
char c = lineIn.charAt(i);
switch (c) {
case '"':
sb.append("&quot;");
break;
case '&':
sb.append("&amp;");
break;
case '\'':
sb.append("&apos;");
break;
case '<':
sb.append("&lt;");
break;
case '>':
sb.append("&gt;");
break;
default: sb.append(c);
}
}
return sb.toString();
}

public static void tableHeader(PrintStream ps, String[] columns) {
ps.print("<tr>");
for (int i = 0; i < columns.length; i++) {
ps.print("<th>");
ps.print(columns[i]);
ps.print("</th>");
}
ps.println("</tr>");
}

public static void tableRow(PrintStream ps, String[] columns) {
ps.print("<tr>");
for (int i = 0; i < columns.length; i++) {
ps.print("<td>");
ps.print(columns[i]);
ps.print("</td>");
}
ps.println("</tr>");
}

public static void main(String[] args) throws Exception {
boolean withTableHeader = (args.length != 0);

InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
PrintStream stdout = System.out;

stdout.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
stdout.println("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
stdout.println("<head><meta http-equiv=\"Content-type\" content=\"text/html;charset=UTF-8\"/>");
stdout.println("<title>CsvToHtmlTable</title>");
stdout.println("<style type=\"text/css\">");
stdout.println("body{background-color:#FFF;color:#000;font-family:OpenSans,sans-serif;font-size:10px;}");
stdout.println("table{border:0.2em solid #2F6FAB;border-collapse:collapse;}");
stdout.println("th{border:0.15em solid #2F6FAB;padding:0.5em;background-color:#E9E9E9;}");
stdout.println("td{border:0.1em solid #2F6FAB;padding:0.5em;background-color:#F9F9F9;}</style>");
stdout.println("</head><body><h1>Csv2Html</h1>");

stdout.println("<table>");
String stdinLine;
boolean firstLine = true;
while ((stdinLine = br.readLine()) != null) {
String[] columns = escapeChars(stdinLine).split(",");
if (withTableHeader == true && firstLine == true) {
tableHeader(stdout, columns);
firstLine = false;
} else {
tableRow(stdout, columns);
}
}
stdout.println("</table></body></html>");

}

}

Add a comment
Know the answer?
Add Answer to:
Please help with this assignment For this assignment, you must design and develop a program to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help with this assignment For this assignment, you must design and develop a program to...

    Please help with this assignment For this assignment, you must design and develop a program to read any CSV file and output an HTML table. The program should be able to input any csv file with any number of fields and use the field headings in the CSV file's first row to become the table headings of the table. The program should output an HTML Bootstrap table with table headings and alternating zebra strips for rows. Your program should demonstrate...

  • IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand...

    IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand the Application The assignment is to first create a class calledTripleString.TripleStringwill consist of threeinstance attribute strings as its basic data. It will also contain a few instance methods to support that data. Once defined, we will use it to instantiate TripleString objects that can be used in our main program. TripleString will contain three member strings as its main data: string1, string2, and string3....

  • In this assignment, you will develop a C program to construct a red and black tree....

    In this assignment, you will develop a C program to construct a red and black tree. For a given input sequence the tree is unique by using RB-INSERT on one number at a time. Below is an example: The input is a sequence of numbers separated by comma, e.g. 1,8,11,2, … You can enter the numbers using an input file and output the tree, or through a command line with one number at a time (with “X” to stop entering...

  • Python Assignment In this assignment, you will use Pandas library to perform analysis on the dataset stored in the following csv file: breast-cancer-wisconsin.csv. Please write script(s) to do the fol...

    Python Assignment In this assignment, you will use Pandas library to perform analysis on the dataset stored in the following csv file: breast-cancer-wisconsin.csv. Please write script(s) to do the following: 1. Read the csv file and covert the dataset into a DataFrame object. 2. Persist the dataset into a SQL table and a JASON file. • Write the content of the DataFrame object into an SQLite database table. This will convert the dataset into a SQL table format. You can...

  • Please write comments with the program. Python programming!! Part III - write student data In this...

    Please write comments with the program. Python programming!! Part III - write student data In this part the program should create a .csv file and fill it with generated student information. The program should: Ask the user for a name for the .csv file (use your own name for the exercise) Create the .csv file with columns named - ID, first-name, GPA Based on the information received in part I, generate and fill students information in the CSV file Tell...

  • Need Help a Intro to Java Programming assignment Design a Area class that has three overloaded...

    Need Help a Intro to Java Programming assignment Design a Area class that has three overloaded static methods areaComputing to calculate the areas of circles, rectangles, and cylinders. Assume that data for circles and cylinders are all doubles and data for rectangles are integers. Code a test program AreaApp by creating at least two objects for each geometric shapes with different hard coded data at your choice for testing.

  • Can you please pick Automobile For this assignment. Java Programming Second Inheritance OOP assignment Outcome: Student...

    Can you please pick Automobile For this assignment. Java Programming Second Inheritance OOP assignment Outcome: Student will demonstrate the ability to use inheritance in Java programs. Program Specifications: Programming assignment: Classes and Inheritance You are to pick your own theme for a new Parent class. You can pick from one of the following: Person Automobile Animal Based on your choice: If you choose Person, you will create a subclass of Person called Student. If you choose Automobile, you will create...

  • Please use python Programming Language: Select one of the following topics: Band Character Account Create a...

    Please use python Programming Language: Select one of the following topics: Band Character Account Create a class based on your chosen topic. Make sure to include at least four attributes of varying types, a constructor, getters/setters for each attribute w/input validation, a toString, a static attribute, and a static method. Then, create a function (outside of your class) that connects to a text file which should contain the attributes of several objects. Read the data from the file, use the...

  • Program Description: Assignment #9 will be the construction of a program that reads in a sequence...

    Program Description: Assignment #9 will be the construction of a program that reads in a sequence of integers from standard input until 0 is read, and store them in an array (including 0). This is done using iteration (choose one of for, while, or do while loop). You may assume that there will not be more than 100 numbers. Then compute the minimum number, count odd integers, compute the sum of numbers that are larger than the first number in...

  • For this project your task is to update the RSS Reader program you wrote for the...

    For this project your task is to update the RSS Reader program you wrote for the previous project so that it reads multiple RSS feeds and generates the same nicely formatted HTML page of links for each feed, plus an HTML index page with links to the individual feed pages. Your new program should ask the user for the name of an XML file containing a list of URLs for RSS v2.0 feeds (see below for the format of this...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT