Reset author name to chosen name ✨
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.chloefontenot.mp2_chloefontenot;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class CheckIBSN_10 {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
// define vars
|
||||
int digit1, digit2, digit3, digit4, digit5, digit6, digit7, digit8, digit9, inputISBN, outputISBN;
|
||||
boolean debug = true;
|
||||
// Scan individual numbers
|
||||
System.out.print("Enter the first 9 digits of an ISBN as an integer: ");
|
||||
inputISBN = input.nextInt(); // Get the first 9 digits of the ISBN
|
||||
|
||||
|
||||
// Divide the number up into 9 digits
|
||||
digit1 = inputISBN / 100000000 % 10;
|
||||
digit2 = inputISBN / 10000000 % 10;
|
||||
digit3 = inputISBN / 1000000 % 10;
|
||||
digit4 = inputISBN / 100000 % 10;
|
||||
digit5 = inputISBN / 10000 % 10;
|
||||
digit6 = inputISBN / 1000 % 10;
|
||||
digit7 = inputISBN / 100 % 10;
|
||||
digit8 = inputISBN / 10 % 10;
|
||||
digit9 = inputISBN / 1 % 10;
|
||||
|
||||
//Print digits for debugging
|
||||
if (debug)
|
||||
{
|
||||
System.out.println("inputISBN: " + inputISBN);
|
||||
System.out.println("ISBN split into 9 digits: " + (digit1) + " " + (digit2) + " " + (digit3) + " " + (digit4) + " " + (digit5) + " " + (digit6) + " " + (digit7) + " " + (digit8) + " " + (digit9));
|
||||
}
|
||||
// Calculate!
|
||||
outputISBN = ((digit1 * 1) + (digit2 * 2) + (digit3 * 3) + (digit4 * 4) + (digit5 * 5) + (digit6 * 6) + (digit7 * 7) + (digit8 * 8) + (digit9 * 9)) % 11;
|
||||
|
||||
//Output
|
||||
if (outputISBN == 10)
|
||||
{
|
||||
System.out.println("The ISBN-10 number is " + digit1+digit2+digit3+digit4+digit5+digit6+digit7+digit8+digit9 + "X");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("The ISBN-10 number is " + digit1+digit2+digit3+digit4+digit5+digit6+digit7+digit8+digit9 + outputISBN);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* 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.chloefontenot.mp2_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class DayOfTheWeek {
|
||||
public static void main(String[] args) {
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
// Define variables
|
||||
int dayOfTheWeek,
|
||||
dayOfTheMonth,
|
||||
century,
|
||||
yearOfTheCentury,
|
||||
month,
|
||||
year;
|
||||
String weekDay = "nullDay";
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Enter year: (e.g., 2022): ");
|
||||
year = input.nextInt();
|
||||
System.out.print("Enter month: 1-12: ");
|
||||
month = input.nextInt();
|
||||
System.out.print("Enter day of the month: 1-31: ");
|
||||
dayOfTheMonth = input.nextInt();
|
||||
|
||||
|
||||
// Calculate
|
||||
century = (year / 100); //We are in the 21st century
|
||||
yearOfTheCentury = year % 100;
|
||||
|
||||
dayOfTheWeek = ((dayOfTheMonth + ((26 * (month + 1)) / 10) + yearOfTheCentury + (yearOfTheCentury / 4) + (century / 4) + (5 * century)) % 7);
|
||||
System.out.println(dayOfTheWeek);
|
||||
|
||||
// Switch moment
|
||||
switch (dayOfTheWeek) {
|
||||
case 0:
|
||||
weekDay = "Saturday";
|
||||
break;
|
||||
case 1:
|
||||
weekDay = "Sunday";
|
||||
break;
|
||||
case 2:
|
||||
weekDay = "Monday";
|
||||
break;
|
||||
case 3:
|
||||
weekDay = "Tuesday";
|
||||
break;
|
||||
case 4:
|
||||
weekDay = "Wednesday";
|
||||
break;
|
||||
case 5:
|
||||
weekDay = "Thursday";
|
||||
break;
|
||||
case 6:
|
||||
weekDay = "Friday";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// Output
|
||||
System.out.println("Day of the week is " + weekDay);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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.chloefontenot.mp2_chloefontenot;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class RandomNumber {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
// Define vars
|
||||
int number = (int) (Math.random() * 12) + 1;
|
||||
System.out.println("Random generated number is " + number);
|
||||
|
||||
//long if else chain
|
||||
if (number == 1)
|
||||
System.out.println("Month is January");
|
||||
else if (number == 2)
|
||||
System.out.println("Month is February");
|
||||
else if (number == 3)
|
||||
System.out.println("Month is March");
|
||||
else if (number == 4)
|
||||
System.out.println("Month is April");
|
||||
else if (number == 5)
|
||||
System.out.println("Month is June");
|
||||
else if (number == 7)
|
||||
System.out.println("Month is July");
|
||||
else if (number == 8)
|
||||
System.out.println("Month is August");
|
||||
else if (number == 9)
|
||||
System.out.println("Month is September");
|
||||
else if (number == 10)
|
||||
System.out.println("Month is October");
|
||||
else if (number == 11)
|
||||
System.out.println("Month is November");
|
||||
else if (number == 12)
|
||||
System.out.println("Month is December");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.chloefontenot.mp2_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class RockPaperScissors {
|
||||
|
||||
public static void main(String[] args) {
|
||||
java.util.Scanner input = new java.util.Scanner(System.in);
|
||||
System.out.println("Rock, Paper, Scissors! Pick a number to continue.");
|
||||
while (true) {
|
||||
int computerNumber = (int) (Math.random() * 3);
|
||||
System.out.print("scissors (0), rock (1), paper (2): ");
|
||||
int userNumber = input.nextInt();
|
||||
System.out.println("computer number: " + computerNumber);
|
||||
switch (computerNumber) {
|
||||
case 0:
|
||||
if (userNumber == 0) {
|
||||
System.out.print("The computer chose scissors. You also picked scissors. It's a draw!");
|
||||
} else if (userNumber == 1) {
|
||||
System.out.print("The computer chose scissors. You picked rock. You won!");
|
||||
} else if (userNumber == 3) {
|
||||
System.out.print("The computer chose scissors. You picked paper. You lost.");
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if (userNumber == 0) {
|
||||
System.out.print("The computer chose rock. You chose scissors. You lost.");
|
||||
} else if (userNumber == 1) {
|
||||
System.out.print("The computer chose rock. You also picked rock. It's a draw!");
|
||||
} else if (userNumber == 3) {
|
||||
System.out.print("The computer chose rock. You picked paper. You won!");
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (userNumber == 0) {
|
||||
System.out.print("The computer chose paper. You picked scissors. You won!");
|
||||
} else if (userNumber == 1) {
|
||||
System.out.print("The computer chose paper. You picked rock. You lost.");
|
||||
} else if (userNumber == 3) {
|
||||
System.out.print("The computer chose paper. You also picked paper. It's a draw!");
|
||||
}
|
||||
break;
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.chloefontenot.mp2_chloefontenot;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class TrianglePerimeter {
|
||||
public static void main(String[] args) {
|
||||
java.util.Scanner input = new java.util.Scanner(System.in);
|
||||
|
||||
// Enter three edges
|
||||
System.out.print("Enter three edges (length in double): ");
|
||||
double edge1 = input.nextDouble(),
|
||||
edge2 = input.nextDouble(),
|
||||
edge3 = input.nextDouble();
|
||||
|
||||
// Display results
|
||||
boolean isValid = (edge1 + edge2 > edge3) && (edge1 + edge3 > edge2) && (edge2 + edge3 > edge1);
|
||||
|
||||
// Display results
|
||||
if (isValid)
|
||||
System.out.println("The perimeter is " + (edge1 + edge2 + edge3));
|
||||
else
|
||||
System.out.println("Input is invalid");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user