Minor Homework help....just want to clean up some things

Everything works fine, I just have two questions:

1. Is there a simple way to center headings and subheadings when writing to a text file?

2. How can I restart the for loop after coming out of the default break of my switch block?

None of these are required for my assignment, I just want to try to do these for my own learning.

The code is as follows:

import java.text.*;//imports java text class

import java.io.*;//imports java io class

publicclass Lab10Rough

{

publicstaticvoid main(String[] args)throws Exception

{

String stuName;

String stuNum;

String courseNamSec;

String numCoursesString;

String gpaOutput;

String letterGradeString;

float gradePoints;

char letterGrade;

double numCourses;

double gpa;

double count;

double sumGradePoints = 0.00;

FileWriter fw =new FileWriter("Lab10.txt");

BufferedWriter bw =new BufferedWriter(fw);

PrintWriter pw =new PrintWriter(bw);

DecimalFormat num =new DecimalFormat("###.00");

InputStreamReader isr =new InputStreamReader(System.in);

BufferedReader br =new BufferedReader(isr);

System.out.print("Enter the number of courses taken: ");

numCoursesString = br.readLine();

numCourses = Double.parseDouble(numCoursesString);

System.out.print("Enter your name: ");

stuName = br.readLine();

System.out.print("Enter your student number: ");

stuNum = br.readLine();

pw.println("Bucks County Community College Grade Report For");

pw.println(stuName);

pw.println(stuNum);

pw.println("Course" +"\t" +"\tGrade" +"\t" +"\tGradepoints");

for(count = 0; count < numCourses; count++)

{

System.out.print("What is your course name and section? (ex. CISC115.59): ");

courseNamSec = br.readLine();

System.out.print("What is your letter grade for the course? (no + or -): ");

letterGradeString = br.readLine();

letterGrade = letterGradeString.charAt(0);

switch(letterGrade)

{

case'A':

case'a':

letterGrade ='A';

gradePoints = 4.00f;

break;

case'B':

case'b':

letterGrade ='B';

gradePoints = 3.00f;

break;

case'C':

case'c':

letterGrade ='C';

gradePoints = 2.00f;

break;

case'D':

case'd':

letterGrade ='D';

gradePoints = 1.00f;

break;

case'F':

case'f':

letterGrade ='F';

gradePoints = 0.00f;

break;

default:

gradePoints = 0.00f;

System.out.println("Invalid letter entry");

break;

}

pw.println(courseNamSec +"\t" +"\t" + letterGrade +"\t" +"\t" + gradePoints);

sumGradePoints += gradePoints;

}

gpa = sumGradePoints / numCourses;

gpaOutput = num.format(gpa);

pw.println("GPA: " + gpaOutput);

pw.close();

}

}

Thanks much!

[5503 byte] By [rjpilla55a] at [2007-11-26 13:12:16]
# 1

1. Is there a simple way to center headings and subheadings when writing to a text file?

No, being centered is a matter of presentation. It depends on the width of the window displaying the text. You can pad the start of the line with spaces, but unless you know the width of the display, it won't be perfect.

2. How can I restart the for loop after coming out of the default break of my switch block?

[url=http://java.sun.com/docs/books/tutorial/java/nutsandbolts/branch.html]continue[/url]

hunter9000a at 2007-7-7 17:29:00 > top of Java-index,Java Essentials,New To Java...
# 2
Thanks much for the link and the info
rjpilla55a at 2007-7-7 17:29:00 > top of Java-index,Java Essentials,New To Java...