93 lines
6.7 KiB
HTML
93 lines
6.7 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||
|
<html>
|
||
|
<head>
|
||
|
<title>DivisionQuiz.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: monospace}
|
||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
|
||
|
table {color: #888888; background-color: #313335; font-family: monospace}
|
||
|
.ST0 {color: #808080; font-family: monospace; font-weight: bold}
|
||
|
.comment {color: #808080}
|
||
|
.whitespace {color: #505050}
|
||
|
.number {color: #6897bb}
|
||
|
.string {color: #6a8759}
|
||
|
.literal {color: #cc7832}
|
||
|
-->
|
||
|
</style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<table width="100%"><tr><td align="center">/home/caleb/NetBeansProjects/ADSV Java/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/DivisionQuiz.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> com.calebfontenot.lab7_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> DivisionQuiz {
|
||
|
|
||
|
<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">// Setup variables</span>
|
||
|
<span class="literal">int</span> number1,
|
||
|
number2,
|
||
|
answerQuotient,
|
||
|
answerRemainder;
|
||
|
<span class="literal">boolean</span> cheatMode = <span class="literal">false</span>; <span class="comment">// Used for debugging</span>
|
||
|
|
||
|
<span class="literal">while</span> (<span class="literal">true</span>) {
|
||
|
<span class="comment">// Get random numbers between 1-100</span>
|
||
|
number1 = (<span class="literal">int</span>) (Math.random() * <span class="number">100</span>);
|
||
|
number2 = (<span class="literal">int</span>) (Math.random() * <span class="number">100</span>);
|
||
|
|
||
|
<span class="comment">// If number1 < number2, flip them</span>
|
||
|
<span class="literal">if</span> (number1 < number2) {
|
||
|
<span class="literal">int</span> tmp = number2;
|
||
|
number2 = number1;
|
||
|
number1 = tmp;
|
||
|
}
|
||
|
|
||
|
<span class="comment">//Prompt</span>
|
||
|
<span class="literal">if</span> (cheatMode == <span class="literal">true</span>) {
|
||
|
System.out.println(<span class="string">"</span><span class="string">CHEAT MODE: the quotient of </span><span class="string">"</span> + number1 + <span class="string">"</span><span class="string"> / </span><span class="string">"</span> + number2 + <span class="string">"</span><span class="string"> is </span><span class="string">"</span> + (number1 / number2));
|
||
|
}
|
||
|
System.out.print(<span class="string">"</span><span class="string"> What is the quotient of </span><span class="string">"</span> + number1 + <span class="string">"</span><span class="string"> / </span><span class="string">"</span> + number2 + <span class="string">"</span><span class="string">? </span><span class="string">"</span>);
|
||
|
answerQuotient = input.nextInt();
|
||
|
<span class="literal">if</span> (cheatMode == <span class="literal">true</span>) {
|
||
|
System.out.println(<span class="string">"</span><span class="string">CHEAT MODE: the remainder of </span><span class="string">"</span> + number1 + <span class="string">"</span><span class="string"> % </span><span class="string">"</span> + number2 + <span class="string">"</span><span class="string"> is </span><span class="string">"</span> + (number1 % number2));
|
||
|
}
|
||
|
System.out.print(<span class="string">"</span><span class="string"> What is the remainder of </span><span class="string">"</span> + number1 + <span class="string">"</span><span class="string"> / </span><span class="string">"</span> + number2 + <span class="string">"</span><span class="string">? </span><span class="string">"</span>);
|
||
|
answerRemainder = input.nextInt();
|
||
|
|
||
|
<span class="comment">// Check if answers are correct</span>
|
||
|
<span class="literal">if</span> ((number1 / number2) == answerQuotient) <span class="comment">//Checks the quotient</span>
|
||
|
{
|
||
|
System.out.println(<span class="string">"</span><span class="string">You are correct about the quotient!</span><span class="string">"</span>);
|
||
|
} <span class="literal">else</span> {
|
||
|
System.out.println(<span class="string">"</span><span class="string">You are wrong about the quotient.</span><span class="string">"</span>);
|
||
|
System.out.println(<span class="string">"</span><span class="string">The quotient of </span><span class="string">"</span> + number1 + <span class="string">"</span><span class="string"> / </span><span class="string">"</span> + number2 + <span class="string">"</span><span class="string"> is </span><span class="string">"</span> + (number1 / number2));
|
||
|
}
|
||
|
<span class="literal">if</span> ((number1 % number2) == answerRemainder) <span class="comment">//Checks the remainder</span>
|
||
|
{
|
||
|
System.out.println(<span class="string">"</span><span class="string">You are correct about the remainder!</span><span class="string">"</span>);
|
||
|
} <span class="literal">else</span> {
|
||
|
System.out.println(<span class="string">"</span><span class="string">You are wrong about the remainder.</span><span class="string">"</span>);
|
||
|
System.out.println(<span class="string">"</span><span class="string">The remainder of </span><span class="string">"</span> + number1 + <span class="string">"</span><span class="string"> % </span><span class="string">"</span> + number2 + <span class="string">"</span><span class="string"> is </span><span class="string">"</span> + (number1 % number2));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
</pre></body>
|
||
|
</html>
|