Reset author name to chosen name ✨
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.lab6_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class If1 {
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.out.println("Please type a positive number: ");
|
||||
|
||||
/*
|
||||
Observe that the varible scan is eliminated
|
||||
Explanation: We create a new object by using "new Scanner" and
|
||||
then the DOT (.) nextInt() uses that new object (new varibale) to read
|
||||
*/
|
||||
int number = new Scanner(System.in).nextInt();
|
||||
|
||||
if ( number >= 0 )
|
||||
System.out.println("You typed a positive number! It was number " + number + "!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* 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.lab6_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class If2 {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Please type a positive number: ");
|
||||
|
||||
if (new Scanner(System.in).nextInt() >= 0 )
|
||||
System.out.println("Tou typed a positive number!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.lab6_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class If3 {
|
||||
public static void main(String[] args) {
|
||||
int number;
|
||||
|
||||
System.out.println("Please type a positive number: ");
|
||||
|
||||
if ( (number = new Scanner(System.in).nextInt() ) >= 0 )
|
||||
System.out.println("Tou typed a positive number. It was number " + number + "!");
|
||||
else
|
||||
System.out.println("You typed a negative number. It was number " + number + "!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* 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.lab6_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class IfElse1 {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Please type a positive number: ");
|
||||
|
||||
/*
|
||||
Observe that the variable scan is eliminated
|
||||
Explanation: We create a new object by using "new Scanner" and
|
||||
then the DOT (.) nextInt() uses that new object (new variable) to read.
|
||||
*/
|
||||
int number = new Scanner(System.in).nextInt();
|
||||
|
||||
if ( number >= 0 )
|
||||
System.out.println("You typed a positive number! It was number " + number + "!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.lab6_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class IfElse2 {
|
||||
public static void main(String[] args) {
|
||||
// Setup variables
|
||||
int number;
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Please enter a even or odd number: ");
|
||||
number = new Scanner(System.in).nextInt(); // Creates scanner just to read a value for number, but doesn't keep the scanner in memory.
|
||||
|
||||
// Determine with if statement and Output
|
||||
if ( number % 2 == 0 ) // An even number when divided by 2 will ALWAYS have a remainder that equals 0
|
||||
{
|
||||
System.out.println("You typed the EVEN number " + number);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("You typed the ODD number " + number);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.lab6_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class IfElse3 {
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Please type today's temperature and I will comment on it: ");
|
||||
Scanner scan = new Scanner(System.in);
|
||||
double todaysTemperature = scan.nextDouble();
|
||||
|
||||
if ( todaysTemperature >= 120)
|
||||
System.out.println("Come on dude! Be serious!");
|
||||
else if ( todaysTemperature >= 100)
|
||||
System.out.println("Very, very hot at " + todaysTemperature + "!");
|
||||
else if ( todaysTemperature >= 85)
|
||||
System.out.println("hot at " + todaysTemperature);
|
||||
else if ( todaysTemperature >= 70 )
|
||||
System.out.println("Pleasant at " + todaysTemperature);
|
||||
else if ( todaysTemperature >= 40 )
|
||||
System.out.println("A bit cold at " + todaysTemperature);
|
||||
else
|
||||
System.out.println("bbbrrrrrrr at " + todaysTemperature + "!");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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.lab6_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class IfElse4 {
|
||||
|
||||
static double inputPrompt() {
|
||||
double grade;
|
||||
System.out.print("Enter your exam grade for it to be letter graded: ");
|
||||
grade = new Scanner(System.in).nextDouble();
|
||||
return grade;
|
||||
}
|
||||
static void ifLogic(double grade) {
|
||||
// Use if else logic and output
|
||||
if (grade > 100) {
|
||||
System.out.println("Your grade seems too high, please try again...");
|
||||
throw new IllegalArgumentException("Invalid grade entered!");
|
||||
}
|
||||
else if ( grade > 90)
|
||||
{
|
||||
System.out.println("Congrats! You got a " + grade + ", which means you got an A!");
|
||||
}
|
||||
else if ( grade > 80)
|
||||
{
|
||||
System.out.println("Good job! You got a " + grade + ", which means you got a B!");
|
||||
}
|
||||
else if ( grade > 70)
|
||||
{
|
||||
System.out.println("Not bad, you got a " + grade + ", which means you got a C.");
|
||||
}
|
||||
else if ( grade > 60)
|
||||
{
|
||||
System.out.println("You got a " + grade + ", which means you got a D.");
|
||||
}
|
||||
else if (grade < 0) {
|
||||
System.out.println("Your grade seems too low, please try again...");
|
||||
throw new IllegalArgumentException("Invalid grade entered!");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Sorry, you got a " + grade + ", so you unfortunately got an F.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Setup variables
|
||||
double grade;
|
||||
String letterGrade;
|
||||
|
||||
while (true) { // Unintended behavior: This will only run twice. I intended this try and catch to run indefinately, but it only will catch once before terminating on its own.
|
||||
// Call ifLogic function
|
||||
try {
|
||||
// Prompt for input
|
||||
grade = inputPrompt();
|
||||
ifLogic(grade);
|
||||
System.exit(0);
|
||||
}
|
||||
catch(Exception IllegalArgumentException) { // ifLogic failed, try again...
|
||||
// Prompt for input
|
||||
grade = inputPrompt();
|
||||
ifLogic(grade);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* 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.chloefontenot.lab6_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Lab6_ChloeFontenot {
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
System.out.println("Please type a positive number: ");
|
||||
Scanner scan = new Scanner(System.in);
|
||||
int number = scan.nextInt();
|
||||
|
||||
if (number >= 0) {
|
||||
System.out.println("You typed a positive number! It was number " + number + "!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.lab6_chloefontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chloe
|
||||
*/
|
||||
public class Triangle {
|
||||
public static void main(String[] args) {
|
||||
// Setup variables
|
||||
double x1,
|
||||
y1,
|
||||
xIntercept;
|
||||
|
||||
// Create scanner
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// Prompt for input
|
||||
System.out.print("Enter a point's x and y coords: ");
|
||||
x1 = input.nextDouble();
|
||||
y1 = input.nextDouble();
|
||||
|
||||
// Calculate!
|
||||
|
||||
// 2. Calculate x by -.5 and add 100 to that
|
||||
xIntercept = ((-0.5 * x1) + 100);
|
||||
System.out.println("x intercept is " + xIntercept);
|
||||
// Check if y is inside of the triangle
|
||||
|
||||
if (y1 <= xIntercept)
|
||||
{
|
||||
System.out.println(x1 +", "+ y1 + " is inside of the triangle!");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println(x1 +", "+ y1 + " is outside of the triangle!");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user