78 lines
6.0 KiB
HTML
78 lines
6.0 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>RockPaperScissors.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; font-weight: bold}
|
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
|
.literal {color: #cc7832}
|
|
.string {color: #6a8759}
|
|
.number {color: #6897bb}
|
|
.comment {color: #808080}
|
|
.whitespace {color: #505050}
|
|
-->
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/MP2_CalebFontenot/src/main/java/com/calebfontenot/mp2_calebfontenot/RockPaperScissors.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.mp2_calebfontenot;
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> <span class="literal">class</span> RockPaperScissors {
|
|
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args) {
|
|
java.util.Scanner input = <span class="literal">new</span> java.util.Scanner(System.in);
|
|
System.out.println(<span class="string">"</span><span class="string">Rock, Paper, Scissors! Pick a number to continue.</span><span class="string">"</span>);
|
|
<span class="literal">while</span> (<span class="literal">true</span>) {
|
|
<span class="literal">int</span> computerNumber = (<span class="literal">int</span>) (Math.random() * <span class="number">3</span>);
|
|
System.out.print(<span class="string">"</span><span class="string">scissors (0), rock (1), paper (2): </span><span class="string">"</span>);
|
|
<span class="literal">int</span> userNumber = input.nextInt();
|
|
System.out.println(<span class="string">"</span><span class="string">computer number: </span><span class="string">"</span> + computerNumber);
|
|
<span class="literal">switch</span> (computerNumber) {
|
|
<span class="literal">case</span> <span class="number">0</span>:
|
|
<span class="literal">if</span> (userNumber == <span class="number">0</span>) {
|
|
System.out.print(<span class="string">"</span><span class="string">The computer chose scissors. You also picked scissors. It's a draw!</span><span class="string">"</span>);
|
|
} <span class="literal">else</span> <span class="literal">if</span> (userNumber == <span class="number">1</span>) {
|
|
System.out.print(<span class="string">"</span><span class="string">The computer chose scissors. You picked rock. You won!</span><span class="string">"</span>);
|
|
} <span class="literal">else</span> <span class="literal">if</span> (userNumber == <span class="number">3</span>) {
|
|
System.out.print(<span class="string">"</span><span class="string">The computer chose scissors. You picked paper. You lost.</span><span class="string">"</span>);
|
|
}
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">1</span>:
|
|
<span class="literal">if</span> (userNumber == <span class="number">0</span>) {
|
|
System.out.print(<span class="string">"</span><span class="string">The computer chose rock. You chose scissors. You lost.</span><span class="string">"</span>);
|
|
} <span class="literal">else</span> <span class="literal">if</span> (userNumber == <span class="number">1</span>) {
|
|
System.out.print(<span class="string">"</span><span class="string">The computer chose rock. You also picked rock. It's a draw!</span><span class="string">"</span>);
|
|
} <span class="literal">else</span> <span class="literal">if</span> (userNumber == <span class="number">3</span>) {
|
|
System.out.print(<span class="string">"</span><span class="string">The computer chose rock. You picked paper. You won!</span><span class="string">"</span>);
|
|
}
|
|
<span class="literal">break</span>;
|
|
<span class="literal">case</span> <span class="number">2</span>:
|
|
<span class="literal">if</span> (userNumber == <span class="number">0</span>) {
|
|
System.out.print(<span class="string">"</span><span class="string">The computer chose paper. You picked scissors. You won!</span><span class="string">"</span>);
|
|
} <span class="literal">else</span> <span class="literal">if</span> (userNumber == <span class="number">1</span>) {
|
|
System.out.print(<span class="string">"</span><span class="string">The computer chose paper. You picked rock. You lost.</span><span class="string">"</span>);
|
|
} <span class="literal">else</span> <span class="literal">if</span> (userNumber == <span class="number">3</span>) {
|
|
System.out.print(<span class="string">"</span><span class="string">The computer chose paper. You also picked paper. It's a draw!</span><span class="string">"</span>);
|
|
}
|
|
<span class="literal">break</span>;
|
|
}
|
|
System.out.println(<span class="string">""</span>);
|
|
}
|
|
}
|
|
}
|
|
|
|
</pre></body>
|
|
</html>
|