Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #53
- //Author RobertGelin
- //This program makes two random numbers and prints the smaller of the two
- import java.util.Random;
- public class numGen53 {
- public static void main(String[] args) {
- Random random = new Random();
- //Generate random numbers
- int firstNUM = random.nextInt(10)+1;
- int secondNUM = random.nextInt(10+1);
- //Set the if-else statements.
- if (firstNUM < secondNUM)
- System.out.println("The smaller number is" + firstNUM);
- else if (secondNUM < firstNUM);
- System.out.println("The smaller number is" + secondNUM);
- }
- }
- #54
- //Author -Robert Gelin
- // This program will take a double as an input and compute the square of that number.
- // It will then output said number.
- import javax.swing.JOptionPane; //Import your packages.
- import java.util.Scanner;
- public class cubeNUM {
- public static void main(String [] args){
- Scanner scan = new Scanner (System.in);
- //Ask the user for an input
- System.out.println("Please enter a double");
- double firstNUM = scan.nextDouble();
- //Calculate your input value
- firstNUM = Math.pow(firstNUM, 3);
- //Display your output value.
- System.out.println(" Your end result is " + firstNUM);
- }
- }
- #55
- /*This program will read a filename from a dialog box. And tell you whether or not it is a valid filename.
- */
- /*
- @author Robert Gelin
- */
- import javax.swing.JOptionPane;
- public class fileReader {
- public static void main(String[] args) {
- //Declare variables
- String fileName;
- String fileExtension;
- int dotLocation;
- fileName = JOptionPane.showInputDialog (null, "Enter a filename");
- dotLocation = fileName.indexOf('.');
- //set up if-else statments to cover possilbe invalid inputs .
- if (dotLocation == -1 )
- JOptionPane.showMessageDialog (null, "No input was found: Derp");
- else
- { dotLocation ++;
- fileExtension = fileName.substring(dotLocation);
- JOptionPane.showMessageDialog(null,"Your filetype is: " + fileExtension);
- }
- }
- }
- #57
- //This program will count a given amount of input (in terms of coins) and output the result in terms of dollars.
- //@author Robert Gelin
- //Import Objects.
- import javax.swing.JOptionPane;
- public class cashCount {
- public static void main(String[] args) {
- double firstBoxValue = Double.parseDouble(JOptionPane.showInputDialog(null, "Please input an amount of change in quarters."));
- //First test run was done here.
- double secondBoxValue = Double.parseDouble(JOptionPane.showInputDialog(null, "Please input a second amount of change in nickels."));
- double thirdBoxValue =Double.parseDouble(JOptionPane.showInputDialog(null, "Please input a third amount of change in dimes"));
- double totalValue = firstBoxValue*.25+ secondBoxValue*.05+ thirdBoxValue*.1;
- JOptionPane.showMessageDialog(null," your total amount of money is: "+ totalValue);
- }
- }
- #63
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement