Lab7
This commit is contained in:
parent
f3bdd89d98
commit
332733653b
2
.gitignore
vendored
2
.gitignore
vendored
@ -2,3 +2,5 @@
|
||||
/lab5_CalebFontenot/target/
|
||||
/LabClass_Sep6_CalebFontenot/target/
|
||||
/lab6_CalebFontenot/target/
|
||||
/03_Sep13_2022/target/
|
||||
/lab7_CalebFontenot/target/
|
||||
|
14
03_Sep13_2022/pom.xml
Normal file
14
03_Sep13_2022/pom.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.calebfontenot._sep13_2022</groupId>
|
||||
<artifactId>03_Sep13_2022</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>18</maven.compiler.source>
|
||||
<maven.compiler.target>18</maven.compiler.target>
|
||||
<exec.mainClass>com.calebfontenot._sep13_2022.App</exec.mainClass>
|
||||
</properties>
|
||||
</project>
|
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
|
||||
*/
|
||||
|
||||
package com.calebfontenot._sep13_2022;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
import java.util.Scanner;
|
||||
|
||||
public class LeapYear {
|
||||
public static void main(String[] args) {
|
||||
// Create a Scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter a year: ");
|
||||
int year = input.nextInt();
|
||||
|
||||
// Check if the year is a leap year
|
||||
boolean isLeapYear =
|
||||
(year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
|
||||
|
||||
// Display the result in a message dialog box
|
||||
System.out.println(year + " is a leap year? " + isLeapYear);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.lab7_calebfontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class And1 {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.out.println("please enter a number between 0 and 10:");
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.lab7_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class DivisionQuiz {
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
// Setup variables
|
||||
int number1,
|
||||
number2,
|
||||
answerQuotient,
|
||||
answerRemainder;
|
||||
boolean cheatMode = false; // Used for debugging
|
||||
|
||||
while (true) {
|
||||
// Get random numbers between 1-100
|
||||
number1 = (int) (Math.random() * 100);
|
||||
number2 = (int) (Math.random() * 100);
|
||||
|
||||
// If number1 < number2, flip them
|
||||
if (number1 < number2) {
|
||||
int tmp = number2;
|
||||
number2 = number1;
|
||||
number1 = tmp;
|
||||
}
|
||||
|
||||
//Prompt
|
||||
if (cheatMode == true) {
|
||||
System.out.println("CHEAT MODE: the quotient of " + number1 + " / " + number2 + " is " + (number1 / number2));
|
||||
}
|
||||
System.out.print(" What is the quotient of " + number1 + " / " + number2 + "? ");
|
||||
answerQuotient = input.nextInt();
|
||||
if (cheatMode == true) {
|
||||
System.out.println("CHEAT MODE: the remainder of " + number1 + " % " + number2 + " is " + (number1 % number2));
|
||||
}
|
||||
System.out.print(" What is the remainder of " + number1 + " / " + number2 + "? ");
|
||||
answerRemainder = input.nextInt();
|
||||
|
||||
// Check if answers are correct
|
||||
if ((number1 / number2) == answerQuotient) //Checks the quotient
|
||||
{
|
||||
System.out.println("You are correct about the quotient!");
|
||||
} else {
|
||||
System.out.println("You are wrong about the quotient.");
|
||||
System.out.println("The quotient of " + number1 + " / " + number2 + " is " + (number1 / number2));
|
||||
}
|
||||
if ((number1 % number2) == answerRemainder) //Checks the remainder
|
||||
{
|
||||
System.out.println("You are correct about the remainder!");
|
||||
} else {
|
||||
System.out.println("You are wrong about the remainder.");
|
||||
System.out.println("The remainder of " + number1 + " % " + number2 + " is " + (number1 % number2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package com.calebfontenot.lab7_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class SubtractionQuiz {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// Create scanner outside of loop so we don't create it over and over again
|
||||
Scanner input = new Scanner(System.in);
|
||||
while(true) {
|
||||
// 1. Generate two random single-digit integers
|
||||
int number1 = (int)(Math.random() * 10);
|
||||
int number2 = (int)(Math.random() * 10);
|
||||
|
||||
// 2. If number < number2, swap number1 with number2
|
||||
if (number1 < number2)
|
||||
{
|
||||
int temp = number1;
|
||||
number1 = number2;
|
||||
number2 = temp;
|
||||
}
|
||||
|
||||
// 3. Prompt the student to answer "what is number1 - number2?"
|
||||
System.out.print("What is " + number1 + " - " + number2 + "? ");
|
||||
int answer = input.nextInt();
|
||||
|
||||
// 4. Grade the answer and display the result
|
||||
if (number1 - number2 == answer)
|
||||
System.out.println("You are correct!");
|
||||
else
|
||||
{
|
||||
System.out.println("Your answer is wrong.");
|
||||
System.out.println(number1 + " - " + number2 + "should be" + (number1 - number2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user