SlideShare a Scribd company logo
JavaCode for Sample Projects
                                   Loops and Conditional StatementsProject

TestAverageAndGrade.java File

importjavax.swing.*;
public class TestAverageAndGrade
{
         public static void main(String[] args)
         {
                  String strScore;
                  double score;
                  doubleaverageTestScore = 0;
                  String grade = "";
                  doublearTestScores[] = new double [5] ;
                  String arLetterGrades[] = new String [5];
                  inttotalNumberOfTests = 5;
                  inttestIdentifier = 1;




Loops and Conditional Statements Project                                     Page 1
while (testIdentifier<= totalNumberOfTests)
               {

               //take string input and convert to double
               strScore = JOptionPane.showInputDialog("Enter the score for Test #" + testIdentifier );
               score = Integer.parseInt(strScore);

               //assign input score to an array of scores
               arTestScores[(testIdentifier - 1)] = score;

               //convert score to letter grade using calculateGrade method and assign to array of grades
               grade = calculateGrade (score);
               arLetterGrades[(testIdentifier - 1)] = grade;

               //increment testIdentifier counter
               testIdentifier = testIdentifier + 1;

               }

               //Reset testIdentifier to 1 for use in reporting
               testIdentifier = 1;

               //calculate average of scores using calculateArAverage method
               averageTestScore = calculateArAverage (arTestScores );

               //Print Report
               System.out.println("TEST_____SCORE_____GRADE");
               while (testIdentifier<= totalNumberOfTests)
               {
                        System.out.println("# " + testIdentifier + "   "+ arTestScores [(testIdentifier - 1)] + " "
                              + arLetterGrades[(testIdentifier - 1)]);
                        testIdentifier = testIdentifier + 1;
               }
                        System.out.println("The average score for all the tests taken is: " + averageTestScore);


Loops and Conditional Statements Project                                                                              Page 2
}

       public static double calculateArAverage (double arNumbers [])
       {
                doublearAverage = 0;
                doublearTotal = 0;
                intnumArElements = 5;
                int count = 0;

               for (count = 0 ; count <numArElements; count++)
               {
                       arTotal = arTotal + arNumbers[count];

               }
               arAverage = (arTotal/numArElements);
               returnarAverage;
       }




Loops and Conditional Statements Project                               Page 3
public static String calculateGrade(double testScore)
       {
                         String letterGrade;
                         if (testScore< 60)
                         {
                                   letterGrade = "F";
                         }
                         else if (testScore< 70)
                         {
                                   letterGrade = "D";
                         }
                         else if (testScore< 80)
                         {
                                   letterGrade = "C";
                         }
                         else if (testScore< 90)
                         {
                                   letterGrade = "B";
                         }
                         else
                         {
                                   letterGrade = "A";
                         }

                               returnletterGrade;
       }

}




Loops and Conditional Statements Project                       Page 4

More Related Content

What's hot

Python ppt
Python pptPython ppt
Python ppt
Rachit Bhargava
 
Python
PythonPython
Python
Aashish Jain
 
Python presentation by Monu Sharma
Python presentation by Monu SharmaPython presentation by Monu Sharma
Python presentation by Monu Sharma
Mayank Sharma
 
Introduction Professional Scrum Developer for Java
Introduction Professional Scrum Developer for JavaIntroduction Professional Scrum Developer for Java
Introduction Professional Scrum Developer for Java
Joris De Winne
 
Yocto Project : Custom Embedded Linux Distribution
Yocto Project : Custom Embedded Linux DistributionYocto Project : Custom Embedded Linux Distribution
Yocto Project : Custom Embedded Linux Distribution
emertxemarketing
 
Android internals 07 - Android graphics (rev_1.1)
Android internals 07 - Android graphics (rev_1.1)Android internals 07 - Android graphics (rev_1.1)
Android internals 07 - Android graphics (rev_1.1)
Egor Elizarov
 
Launch the First Process in Linux System
Launch the First Process in Linux SystemLaunch the First Process in Linux System
Launch the First Process in Linux System
Jian-Hong Pan
 
Embedded C
Embedded CEmbedded C
Embedded linux
Embedded linuxEmbedded linux
Embedded linux
Wingston
 
Python basics
Python basicsPython basics
Python basics
Hoang Nguyen
 
Algorithms KS1 & KS2
Algorithms KS1 & KS2Algorithms KS1 & KS2
Algorithms KS1 & KS2
Yasemin Allsop
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Unit 2 python
Unit 2 pythonUnit 2 python
Unit 2 python
praveena p
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
KrishnaMildain
 
Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Python ppt
Python pptPython ppt
Python ppt
Rohit Verma
 
Linux programming - Getting self started
Linux programming - Getting self started Linux programming - Getting self started
Linux programming - Getting self started
Emertxe Information Technologies Pvt Ltd
 
Intro to Python for Non-Programmers
Intro to Python for Non-ProgrammersIntro to Python for Non-Programmers
Intro to Python for Non-Programmers
Ahmad Alhour
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
Kevlin Henney
 

What's hot (20)

Python ppt
Python pptPython ppt
Python ppt
 
Python
PythonPython
Python
 
Python presentation by Monu Sharma
Python presentation by Monu SharmaPython presentation by Monu Sharma
Python presentation by Monu Sharma
 
Introduction Professional Scrum Developer for Java
Introduction Professional Scrum Developer for JavaIntroduction Professional Scrum Developer for Java
Introduction Professional Scrum Developer for Java
 
Yocto Project : Custom Embedded Linux Distribution
Yocto Project : Custom Embedded Linux DistributionYocto Project : Custom Embedded Linux Distribution
Yocto Project : Custom Embedded Linux Distribution
 
Android internals 07 - Android graphics (rev_1.1)
Android internals 07 - Android graphics (rev_1.1)Android internals 07 - Android graphics (rev_1.1)
Android internals 07 - Android graphics (rev_1.1)
 
Launch the First Process in Linux System
Launch the First Process in Linux SystemLaunch the First Process in Linux System
Launch the First Process in Linux System
 
Embedded C
Embedded CEmbedded C
Embedded C
 
Embedded linux
Embedded linuxEmbedded linux
Embedded linux
 
Python basics
Python basicsPython basics
Python basics
 
Algorithms KS1 & KS2
Algorithms KS1 & KS2Algorithms KS1 & KS2
Algorithms KS1 & KS2
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Unit 2 python
Unit 2 pythonUnit 2 python
Unit 2 python
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
 
Embedded Linux on ARM
Embedded Linux on ARMEmbedded Linux on ARM
Embedded Linux on ARM
 
Python ppt
Python pptPython ppt
Python ppt
 
Python - the basics
Python - the basicsPython - the basics
Python - the basics
 
Linux programming - Getting self started
Linux programming - Getting self started Linux programming - Getting self started
Linux programming - Getting self started
 
Intro to Python for Non-Programmers
Intro to Python for Non-ProgrammersIntro to Python for Non-Programmers
Intro to Python for Non-Programmers
 
Python Advanced – Building on the foundation
Python Advanced – Building on the foundationPython Advanced – Building on the foundation
Python Advanced – Building on the foundation
 

Similar to Java Code for Sample Projects Loops

STAMP ActiveEon Use Case at Telecom Valley Dec. 2018
STAMP ActiveEon Use Case at Telecom Valley Dec. 2018STAMP ActiveEon Use Case at Telecom Valley Dec. 2018
STAMP ActiveEon Use Case at Telecom Valley Dec. 2018
STAMP Project
 
Software testing lab manual
Software testing lab manualSoftware testing lab manual
Software testing lab manual
Tanzeem Syed
 
Top 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdetTop 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdet
DevLabs Alliance
 
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdfSolve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
snewfashion
 
How to not write a boring test in Golang
How to not write a boring test in GolangHow to not write a boring test in Golang
How to not write a boring test in Golang
Dan Tran
 
Write a program Grader that that will be used by a program driver to.pdf
Write a program Grader that that will be used by a program driver to.pdfWrite a program Grader that that will be used by a program driver to.pdf
Write a program Grader that that will be used by a program driver to.pdf
arjunenterprises1978
 
"How keep normal blood pressure using TDD" By Roman Loparev
"How keep normal blood pressure using TDD" By Roman Loparev"How keep normal blood pressure using TDD" By Roman Loparev
"How keep normal blood pressure using TDD" By Roman Loparev
Ciklum Ukraine
 
Implement the Queue ADT using array – based approach. Using C++ prog.pdf
Implement the Queue ADT using array – based approach. Using C++ prog.pdfImplement the Queue ADT using array – based approach. Using C++ prog.pdf
Implement the Queue ADT using array – based approach. Using C++ prog.pdf
sktambifortune
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdf
Chen-Hung Hu
 
Alexey Tsoy Meta Programming in C++ 16.11.17
Alexey Tsoy Meta Programming in C++ 16.11.17Alexey Tsoy Meta Programming in C++ 16.11.17
Alexey Tsoy Meta Programming in C++ 16.11.17
LogeekNightUkraine
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsHCMUTE
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorNeeraj Kaushik
 
Developer Testing Tools Roundup
Developer Testing Tools RoundupDeveloper Testing Tools Roundup
Developer Testing Tools Roundup
John Ferguson Smart Limited
 
A Test of Strength
A Test of StrengthA Test of Strength
A Test of Strength
Chris Oldwood
 
How to write clean tests
How to write clean testsHow to write clean tests
How to write clean tests
Danylenko Max
 
Is your C# optimized
Is your C# optimizedIs your C# optimized
Is your C# optimizedWoody Pewitt
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
imtiazalijoono
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing Speed
Pascal-Louis Perez
 
lesson 2.pptx
lesson 2.pptxlesson 2.pptx
lesson 2.pptx
khaledahmed316
 

Similar to Java Code for Sample Projects Loops (20)

STAMP ActiveEon Use Case at Telecom Valley Dec. 2018
STAMP ActiveEon Use Case at Telecom Valley Dec. 2018STAMP ActiveEon Use Case at Telecom Valley Dec. 2018
STAMP ActiveEon Use Case at Telecom Valley Dec. 2018
 
Software testing lab manual
Software testing lab manualSoftware testing lab manual
Software testing lab manual
 
Top 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdetTop 20 java programming interview questions for sdet
Top 20 java programming interview questions for sdet
 
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdfSolve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
Solve the coding errors for upvotemake test-statsg++ -g -std=c++.pdf
 
How to not write a boring test in Golang
How to not write a boring test in GolangHow to not write a boring test in Golang
How to not write a boring test in Golang
 
Write a program Grader that that will be used by a program driver to.pdf
Write a program Grader that that will be used by a program driver to.pdfWrite a program Grader that that will be used by a program driver to.pdf
Write a program Grader that that will be used by a program driver to.pdf
 
"How keep normal blood pressure using TDD" By Roman Loparev
"How keep normal blood pressure using TDD" By Roman Loparev"How keep normal blood pressure using TDD" By Roman Loparev
"How keep normal blood pressure using TDD" By Roman Loparev
 
Implement the Queue ADT using array – based approach. Using C++ prog.pdf
Implement the Queue ADT using array – based approach. Using C++ prog.pdfImplement the Queue ADT using array – based approach. Using C++ prog.pdf
Implement the Queue ADT using array – based approach. Using C++ prog.pdf
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdf
 
Alexey Tsoy Meta Programming in C++ 16.11.17
Alexey Tsoy Meta Programming in C++ 16.11.17Alexey Tsoy Meta Programming in C++ 16.11.17
Alexey Tsoy Meta Programming in C++ 16.11.17
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression Calculator
 
Developer Testing Tools Roundup
Developer Testing Tools RoundupDeveloper Testing Tools Roundup
Developer Testing Tools Roundup
 
A Test of Strength
A Test of StrengthA Test of Strength
A Test of Strength
 
How to write clean tests
How to write clean testsHow to write clean tests
How to write clean tests
 
Is your C# optimized
Is your C# optimizedIs your C# optimized
Is your C# optimized
 
Comp102 lec 5.1
Comp102   lec 5.1Comp102   lec 5.1
Comp102 lec 5.1
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing Speed
 
lesson 2.pptx
lesson 2.pptxlesson 2.pptx
lesson 2.pptx
 

More from jwjablonski

Amazing Books Database Objects, Reports and Forms
Amazing Books Database Objects, Reports and FormsAmazing Books Database Objects, Reports and Forms
Amazing Books Database Objects, Reports and Formsjwjablonski
 
Study Skills Project
Study Skills ProjectStudy Skills Project
Study Skills Projectjwjablonski
 
Java Code For Sample Projects I/O
Java Code For Sample Projects I/OJava Code For Sample Projects I/O
Java Code For Sample Projects I/Ojwjablonski
 
Java Code for Sample Projects Methods
Java Code for Sample Projects MethodsJava Code for Sample Projects Methods
Java Code for Sample Projects Methodsjwjablonski
 
Java Code for Sample Projects Inheritance
Java Code for Sample Projects InheritanceJava Code for Sample Projects Inheritance
Java Code for Sample Projects Inheritancejwjablonski
 
VBA Final Project
VBA Final ProjectVBA Final Project
VBA Final Projectjwjablonski
 
PL/SQL Code for Sample Projects
PL/SQL Code for Sample ProjectsPL/SQL Code for Sample Projects
PL/SQL Code for Sample Projectsjwjablonski
 
Animal Shelter Database Presentation
Animal Shelter Database PresentationAnimal Shelter Database Presentation
Animal Shelter Database Presentationjwjablonski
 

More from jwjablonski (11)

Portfolio
PortfolioPortfolio
Portfolio
 
Amazing Books Database Objects, Reports and Forms
Amazing Books Database Objects, Reports and FormsAmazing Books Database Objects, Reports and Forms
Amazing Books Database Objects, Reports and Forms
 
Study Skills Project
Study Skills ProjectStudy Skills Project
Study Skills Project
 
Java Code For Sample Projects I/O
Java Code For Sample Projects I/OJava Code For Sample Projects I/O
Java Code For Sample Projects I/O
 
Java Code for Sample Projects Methods
Java Code for Sample Projects MethodsJava Code for Sample Projects Methods
Java Code for Sample Projects Methods
 
Java Code for Sample Projects Inheritance
Java Code for Sample Projects InheritanceJava Code for Sample Projects Inheritance
Java Code for Sample Projects Inheritance
 
VBA Final Project
VBA Final ProjectVBA Final Project
VBA Final Project
 
PL/SQL Code for Sample Projects
PL/SQL Code for Sample ProjectsPL/SQL Code for Sample Projects
PL/SQL Code for Sample Projects
 
Animal Shelter Database Presentation
Animal Shelter Database PresentationAnimal Shelter Database Presentation
Animal Shelter Database Presentation
 
Hangman Program
Hangman ProgramHangman Program
Hangman Program
 
Cents Add Up
Cents Add Up Cents Add Up
Cents Add Up
 

Java Code for Sample Projects Loops

  • 1. JavaCode for Sample Projects Loops and Conditional StatementsProject TestAverageAndGrade.java File importjavax.swing.*; public class TestAverageAndGrade { public static void main(String[] args) { String strScore; double score; doubleaverageTestScore = 0; String grade = ""; doublearTestScores[] = new double [5] ; String arLetterGrades[] = new String [5]; inttotalNumberOfTests = 5; inttestIdentifier = 1; Loops and Conditional Statements Project Page 1
  • 2. while (testIdentifier<= totalNumberOfTests) { //take string input and convert to double strScore = JOptionPane.showInputDialog("Enter the score for Test #" + testIdentifier ); score = Integer.parseInt(strScore); //assign input score to an array of scores arTestScores[(testIdentifier - 1)] = score; //convert score to letter grade using calculateGrade method and assign to array of grades grade = calculateGrade (score); arLetterGrades[(testIdentifier - 1)] = grade; //increment testIdentifier counter testIdentifier = testIdentifier + 1; } //Reset testIdentifier to 1 for use in reporting testIdentifier = 1; //calculate average of scores using calculateArAverage method averageTestScore = calculateArAverage (arTestScores ); //Print Report System.out.println("TEST_____SCORE_____GRADE"); while (testIdentifier<= totalNumberOfTests) { System.out.println("# " + testIdentifier + " "+ arTestScores [(testIdentifier - 1)] + " " + arLetterGrades[(testIdentifier - 1)]); testIdentifier = testIdentifier + 1; } System.out.println("The average score for all the tests taken is: " + averageTestScore); Loops and Conditional Statements Project Page 2
  • 3. } public static double calculateArAverage (double arNumbers []) { doublearAverage = 0; doublearTotal = 0; intnumArElements = 5; int count = 0; for (count = 0 ; count <numArElements; count++) { arTotal = arTotal + arNumbers[count]; } arAverage = (arTotal/numArElements); returnarAverage; } Loops and Conditional Statements Project Page 3
  • 4. public static String calculateGrade(double testScore) { String letterGrade; if (testScore< 60) { letterGrade = "F"; } else if (testScore< 70) { letterGrade = "D"; } else if (testScore< 80) { letterGrade = "C"; } else if (testScore< 90) { letterGrade = "B"; } else { letterGrade = "A"; } returnletterGrade; } } Loops and Conditional Statements Project Page 4