Moving Right Along in CS 0007, Intro to Programming in Java | Tiffany R. White Blog

Moving Right Along in CS 0007, Intro to Programming in Java

Reading time: 2 mins

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);
  }
}





Share

No Ads. No Sponsored Content. Ever.

I've decided that I no longer want to have sponsored posts on this blog. I also, though as tempting as it may sound, don't want ads; even if I got big enough for Carbon ads I don't want them. I want to post free, engaging content for beginning/junior devs. This means that I won't have Setapp posts or affiliates on this blog, though I will keep them on the Uses page. If you enjoy the content, buy me a coffee. Just click the button below.


Coffee Buy me a coffeeBuy me a coffee


Webmentions 0

No webmentions were found.

Newsletter