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

In addition to Java code, your project will contain \"P5Demo.jar\" and \"states.

ID: 671962 • Letter: I

Question

In addition to Java code, your project will contain "P5Demo.jar" and "states.txt".

Look at "states.txt". It is a text file in which each line of text consists of a state name, followed by a tab character, followed by a double literal. It is sample input for the program that you will be completing.

Now run "PSDemo.jar" by double clicking on it. Click on the "Load Data" button and open "statest.txt". Experiment with the various controls at the top and along the right of the window. Your job in this assignment is to make your project behave like this executable jar file.

Your Task

To make your project behave like "PSDemo.jar", you will need to implement the three methods that are specified in the GraphicsMethods class. Read the specifications carefully, because they are very detailed.

The three methods in GraphicsMethods have simple skeleton implementations that, while incorrect, allow the application to run.

The purpose of this assignment is to give you practice with procedural design. The methods are complicated enough that you are going to almost certainly want to design and implement helper methods.

For each method that you implement---whenever it is one of my methods or one of your helpers---you are to create JUnit test cases that test it thoroughly. The only exception is for methods that draw with a Graphics object, as there is no easy way to make assertions about graphics.

Here's how you should proceed:

Create a set of JUnit test cases for the summarizeData and readTable methods. This will have the benefit of helping you understand what they are supposed to do. I have included one unit test that illustrates how to make assertions about ArrayLists.

Sit and think about you will go about implementing the three methods. Work through examples on paper. When you identify helper methods that would make your life easier, create stubs and test cases for them.

Explanation / Answer

package net.viralpatel.itext.pdf;

import org.jfree.chart.ChartFactory;

import org.jfree.chart.JFreeChart;

import org.jfree.chart.plot.PlotOrientation;

import org.jfree.data.category.DefaultCategoryDataset;

import org.jfree.data.general.DefaultPieDataset;

public class PieChartDemo {

    public static void main(String[] args) {

        //TODO: Add code to generate PDFs with charts

    }

    public static JFreeChart generatePieChart() {

        DefaultPieDataset dataSet = new DefaultPieDataset();

        dataSet.setValue("China", 19.64);

        dataSet.setValue("India", 17.3);

        dataSet.setValue("United States", 4.54);

        dataSet.setValue("Indonesia", 3.4);

        dataSet.setValue("Brazil", 2.83);

        dataSet.setValue("Pakistan", 2.48);

        dataSet.setValue("Bangladesh", 2.38);

        JFreeChart chart = ChartFactory.createPieChart(

                "World Population by countries", dataSet, true, true, false);

        return chart;

    }

    public static JFreeChart generateBarChart() {

        DefaultCategoryDataset dataSet = new DefaultCategoryDataset();

        dataSet.setValue(791, "Population", "1750 AD");

        dataSet.setValue(978, "Population", "1800 AD");

        dataSet.setValue(1262, "Population", "1850 AD");

        dataSet.setValue(1650, "Population", "1900 AD");

        dataSet.setValue(2519, "Population", "1950 AD");

        dataSet.setValue(6070, "Population", "2000 AD");

        JFreeChart chart = ChartFactory.createBarChart(

                "World Population growth", "Year", "Population in millions",

                dataSet, PlotOrientation.VERTICAL, false, true, false);

        return chart;

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote