SpreadsheetWriterjava Can you please help me the JAVA progra
SpreadsheetWriter.java
Can you please help me the JAVA program?
Let\'s write a program that will produce a file that can be opened by Excel or LibreOffice Calc. Go to Getting Started and look up the grading weights used for this course. As an example, we\'ll use the following table, but you should use the values you find in Getting Started. Write a class SSRow. Objects of this class should keep track of String name, int score, int weight, String calc. SSRow also has a to String method that returns this data in order, separated by commas. name + \", \"+ score +\", \"+ weight +\", \"+ calc Further design of the SSRow class is left to you. Add what you need, but don\'t get carried away. Write a class SSWriter that has a main method. For each of the grading categories (Lab. Reading Quizzes. Group Work. Midterm. Project. Final. Instructor Discretion). query the user for a score, and create the following SSRow objects: \"Lab\", : 20. \"=B1Times C1/100\" \"Reading Quizzes\". , 10, \"=B2TimesC2/100\" \"Group Work\". , 10, \"=B3 Times C3/100\" \"Midterm\". . 20, \"=B4 Times C4/100\" \"Project\", . 15, \"=B5 Times C5/100\" \"Final\", . 20, \"=B6 Times C6/100\" \"Instructor Discretion\". , 5, \"=B7 Times C7/100\" Open a file for output with a file type of csv (say MyGrades.csv, for example). Write the to String value for each SSRow to the file. Finally, write a row \"average\".=(D1+D2+D3+D4+D5+D6+D7) Open MyGrades.csv with Excel or LibreOffice Calc.Solution
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
class SSRow{
String name;
int score;
int weight;
String cal;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public String getCal() {
return cal;
}
public void setCal(String cal) {
this.cal = cal;
}
@Override
public String toString() {
return \"\\\"\" + name + \"\\\", \\\"\" + score + \"\\\", \\\"\" + weight + \"\\\", \\\"\" + cal + \"\\\"\";
}
}
public class SSWriter {
// Maintain a static map b/w workType and weights
private static final Map<String, Integer> WORK_TYPE_TO_WEIGHT_MAP = new LinkedHashMap<>();
static {
WORK_TYPE_TO_WEIGHT_MAP.put(\"Lab\", 20);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Reading Quizzes\", 10);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Group Work\", 10);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Midterm\", 20);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Project\", 15);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Final\", 20);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Instructor Discretion\", 5);
}
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
ArrayList<SSRow> list = new ArrayList<>(); // List to maintain the rows
int index = 1;
String avgString = \"\";
for(String workType : WORK_TYPE_TO_WEIGHT_MAP.keySet()){
System.out.println(\"Please enter the score for \"+workType+\": \");
int score = scanner.nextInt();
// Create a SSRow and set the parameters
SSRow ssRow = new SSRow();
ssRow.setName(workType);
ssRow.setScore(score);
ssRow.setWeight(WORK_TYPE_TO_WEIGHT_MAP.get(workType));
ssRow.setCal(\"=B\"+index +\"*C\"+index+\"/100\");
list.add(ssRow);
if(index == 1) avgString +=\"=D\"+index;
else avgString+= \"+D\"+index;
index++;
}
avgString = \"\\\"\"+avgString+\"\\\"\";
PrintWriter printer = new PrintWriter(new FileWriter(\"/home/kumar/Desktop/MyGrades.csv\"), true);
for(SSRow ssRow : list){
printer.println(ssRow); // Write one row at a time
}
printer.println(\"\\\"average\\\", \"+avgString); // Append average row
scanner.close(); // close the resources after using
printer.close();
System.out.println(\"Program execution completed.\");
}
}
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
class SSRow{
String name;
int score;
int weight;
String cal;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public String getCal() {
return cal;
}
public void setCal(String cal) {
this.cal = cal;
}
@Override
public String toString() {
return \"\\\"\" + name + \"\\\", \\\"\" + score + \"\\\", \\\"\" + weight + \"\\\", \\\"\" + cal + \"\\\"\";
}
}
public class SSWriter {
// Maintain a static map b/w workType and weights
private static final Map<String, Integer> WORK_TYPE_TO_WEIGHT_MAP = new LinkedHashMap<>();
static {
WORK_TYPE_TO_WEIGHT_MAP.put(\"Lab\", 20);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Reading Quizzes\", 10);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Group Work\", 10);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Midterm\", 20);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Project\", 15);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Final\", 20);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Instructor Discretion\", 5);
}
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
ArrayList<SSRow> list = new ArrayList<>(); // List to maintain the rows
int index = 1;
String avgString = \"\";
for(String workType : WORK_TYPE_TO_WEIGHT_MAP.keySet()){
System.out.println(\"Please enter the score for \"+workType+\": \");
int score = scanner.nextInt();
// Create a SSRow and set the parameters
SSRow ssRow = new SSRow();
ssRow.setName(workType);
ssRow.setScore(score);
ssRow.setWeight(WORK_TYPE_TO_WEIGHT_MAP.get(workType));
ssRow.setCal(\"=B\"+index +\"*C\"+index+\"/100\");
list.add(ssRow);
if(index == 1) avgString +=\"=D\"+index;
else avgString+= \"+D\"+index;
index++;
}
avgString = \"\\\"\"+avgString+\"\\\"\";
PrintWriter printer = new PrintWriter(new FileWriter(\"/home/kumar/Desktop/MyGrades.csv\"), true);
for(SSRow ssRow : list){
printer.println(ssRow); // Write one row at a time
}
printer.println(\"\\\"average\\\", \"+avgString); // Append average row
scanner.close(); // close the resources after using
printer.close();
System.out.println(\"Program execution completed.\");
}
}
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
class SSRow{
String name;
int score;
int weight;
String cal;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
public String getCal() {
return cal;
}
public void setCal(String cal) {
this.cal = cal;
}
@Override
public String toString() {
return \"\\\"\" + name + \"\\\", \\\"\" + score + \"\\\", \\\"\" + weight + \"\\\", \\\"\" + cal + \"\\\"\";
}
}
public class SSWriter {
// Maintain a static map b/w workType and weights
private static final Map<String, Integer> WORK_TYPE_TO_WEIGHT_MAP = new LinkedHashMap<>();
static {
WORK_TYPE_TO_WEIGHT_MAP.put(\"Lab\", 20);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Reading Quizzes\", 10);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Group Work\", 10);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Midterm\", 20);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Project\", 15);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Final\", 20);
WORK_TYPE_TO_WEIGHT_MAP.put(\"Instructor Discretion\", 5);
}
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
ArrayList<SSRow> list = new ArrayList<>(); // List to maintain the rows
int index = 1;
String avgString = \"\";
for(String workType : WORK_TYPE_TO_WEIGHT_MAP.keySet()){
System.out.println(\"Please enter the score for \"+workType+\": \");
int score = scanner.nextInt();
// Create a SSRow and set the parameters
SSRow ssRow = new SSRow();
ssRow.setName(workType);
ssRow.setScore(score);
ssRow.setWeight(WORK_TYPE_TO_WEIGHT_MAP.get(workType));
ssRow.setCal(\"=B\"+index +\"*C\"+index+\"/100\");
list.add(ssRow);
if(index == 1) avgString +=\"=D\"+index;
else avgString+= \"+D\"+index;
index++;
}
avgString = \"\\\"\"+avgString+\"\\\"\";
PrintWriter printer = new PrintWriter(new FileWriter(\"/home/kumar/Desktop/MyGrades.csv\"), true);
for(SSRow ssRow : list){
printer.println(ssRow); // Write one row at a time
}
printer.println(\"\\\"average\\\", \"+avgString); // Append average row
scanner.close(); // close the resources after using
printer.close();
System.out.println(\"Program execution completed.\");
}
}
| |||||||













