new semester, new repo structure
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>FindTwoHighestScoresWhile.java</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
body {color: #a9b7c6; background-color: #2b2b2b; font-family: Ubuntu}
|
||||
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: Ubuntu}
|
||||
table {color: #888888; background-color: #313335; font-family: Ubuntu}
|
||||
.literal {color: #cc7832}
|
||||
.number {color: #6897bb}
|
||||
.string {color: #6a8759}
|
||||
.comment {color: #808080}
|
||||
.whitespace {color: #505050}
|
||||
.ST0 {color: #808080; font-family: Ubuntu; font-weight: bold}
|
||||
-->
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/MP3_CalebFontenot/src/mp3_calebfontenot/FindTwoHighestScoresWhile.java</td></tr></table>
|
||||
<pre>
|
||||
<span class="comment">/*</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
|
||||
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
|
||||
<span class="comment"> */</span>
|
||||
<span class="literal">package</span> mp3_calebfontenot;
|
||||
|
||||
<span class="literal">import</span> java.util.Scanner;
|
||||
|
||||
<span class="comment">/**</span>
|
||||
<span class="comment"> *</span>
|
||||
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">caleb</span>
|
||||
<span class="comment">*/</span>
|
||||
<span class="literal">public</span> <span class="literal">class</span> FindTwoHighestScoresWhile {
|
||||
|
||||
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
|
||||
<span class="comment">// Create scanner</span>
|
||||
Scanner input = <span class="literal">new</span> Scanner(System.in);
|
||||
|
||||
<span class="comment">// Define variables</span>
|
||||
<span class="literal">double</span> highScore1 = <span class="number">0</span>, highScore2 = <span class="number">0</span>, score;
|
||||
String bestStudent1 = <span class="string">""</span>, bestStudent2 = <span class="string">""</span>, student;
|
||||
<span class="literal">int</span> numberToIterate = <span class="number">0</span>;
|
||||
|
||||
<span class="comment">// Compute</span>
|
||||
System.out.print(<span class="string">"</span><span class="string">Enter the number of students: </span><span class="string">"</span>);
|
||||
numberToIterate = input.nextInt();
|
||||
<span class="literal">int</span> i = <span class="number">0</span>;
|
||||
<span class="literal">while</span> (i != numberToIterate) {
|
||||
System.out.print(<span class="string">"</span><span class="string">Enter a student name: </span><span class="string">"</span>);
|
||||
student = input.next();
|
||||
System.out.print(<span class="string">"</span><span class="string">Enter </span><span class="string">"</span> + student + <span class="string">"</span><span class="string">'s score: </span><span class="string">"</span>);
|
||||
score = input.nextDouble();
|
||||
|
||||
<span class="literal">if</span> (score > highScore1) { <span class="comment">// New high score detected</span>
|
||||
|
||||
<span class="literal">if</span> (highScore1 != <span class="number">0</span>) {
|
||||
highScore2 = highScore1; <span class="comment">// assign highScore1 to highScore2</span>
|
||||
bestStudent2 = bestStudent1;
|
||||
}
|
||||
highScore1 = score; <span class="comment">// assign current score to high score</span>
|
||||
bestStudent1 = student;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
System.out.println(<span class="string">"</span><span class="string">Best score belongs to </span><span class="string">"</span> + bestStudent1 + <span class="string">"</span><span class="string">, with a score of </span><span class="string">"</span> + highScore1);
|
||||
System.out.println(<span class="string">"</span><span class="string">Next best score belongs to </span><span class="string">"</span> + bestStudent2 + <span class="string">"</span><span class="string">, with a score of </span><span class="string">"</span> + highScore2);
|
||||
}
|
||||
}
|
||||
|
||||
</pre></body>
|
||||
</html>
|
Reference in New Issue
Block a user