2 min read

The Blank Text Editor

Text_Wrangler

So class is moving along at a regular clip. I am learning about syntax and seeing similarities between other languages. I have written four text-based programs using Java that were pretty easy, seeing as I already have some clue as to how to code. Today, however, she threw us into the fire and, like many times before, I opened up a blank Atom text document and froze.

Fear of Getting It Wrong

I know I am going to write bugs. Everyone does. No one gets it write the first time. But sitting there at my Mac, staring at Atom, knowing I had a day to complete calculating the average of three test scores and then printing the average to the screen using two decimal places stopped me in my tracks. We just learned about formatters, which I was familiar with in Python, but there was this extra way to format. For instance, take the number 5,876.98. You could format this like:

 public class Tax Ripoff
{
 public static void main(String[] args)
  {
  double grossPay = 5876.98
  double netPay = 5489.76
  double differenceInPay = grossPay - netPay;
  System.out.printf("The difference between your gross and net pay is %,.2f\n", differenceInPay);
  }
}



 public class Tax Ripoff
{
 public static void main(String[] args)
  {
  double grossPay = 5876.98
  double netPay = 5489.76
  double differenceInPay = grossPay - netPay;
  System.out.printf("The difference between your gross and net pay is %,.2f\n", differenceInPay);
  }
}




I don’t know if they have that in Python, but it looks pretty silly and verbose to me. Anyway. I completely froze up. I do it all the time. I am a perfectionist. To a fault. This can’t happen if I am to get anything done. So I looked at my professor’s code and my old code and started coding.

Bugs

Ran into a bug. Thanks to Bill Laboon for his help debugging. I kept getting an exception error. I was using “%,.2f” when my numbers didn’t require a comma– they weren’t big enough. So my program is full of whitespace which I am going to fix, just want to read it better. This is the program I wrote:
import java.util.Scanner;

public class White
{
 public static void main(String[] args)
 {
 Scanner keyboard = new Scanner(System.in);

 System.out.print("Enter your first test score.");
 double firstScore = keyboard.nextDouble();

 System.out.print("Enter your second test score.");
 double secondScore = keyboard.nextDouble();

 System.out.print("Enter your third test score.");
 double thirdScore = keyboard.nextDouble();

 double totalScore = (firstScore + secondScore + thirdScore) / 3;

System.out.printf("Your class average is %.2f\n", totalScore);
  }
}



import java.util.Scanner;

public class White
{
 public static void main(String[] args)
 {
 Scanner keyboard = new Scanner(System.in);

 System.out.print("Enter your first test score.");
 double firstScore = keyboard.nextDouble();

 System.out.print("Enter your second test score.");
 double secondScore = keyboard.nextDouble();

 System.out.print("Enter your third test score.");
 double thirdScore = keyboard.nextDouble();

 double totalScore = (firstScore + secondScore + thirdScore) / 3;

System.out.printf("Your class average is %.2f\n", totalScore);
  }
}