Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program that determines type of website:
- package com.Suarez;
- /*
- Xander fermier
- 1/16/19
- the user inputs a url and based on the last four characters the computer determines what type of address it is
- */
- import java.util.*;
- public class TypeOfWebsite {
- public static void main(String[] args)
- {
- System.out.println("Enter a website");
- Scanner web = new Scanner(System.in);
- String url = web.nextLine();
- int webLength = url.length();
- String webType = url.substring(webLength-4);
- switch (webType)
- {
- case ".gov":
- System.out.println("It is a government web address.");
- break;
- case ".edu":
- System.out.println("It is a university web address");
- break;
- case ".com":
- System.out.println("It is a business web address");
- break;
- case ".org":
- System.out.println("It is an organization web address");
- break;
- default:
- System.out.println("It is a web address for another entity");
- break;
- }
- }
- }
- Program that gives likely season:
- package com.Suarez;
- /*
- xander fermier
- 1/16/19
- the user inputs a range and based on the range the computer will output the likely season
- */
- import java.util.*;
- public class temperatureRangeGuess {
- public static void main(String []args)
- {
- System.out.println("Give me a temperature and I will predict the season.");
- Scanner tempInput = new Scanner(System.in);
- int temp = tempInput.nextInt();
- if (temp > 90 && temp < 110)
- {
- System.out.println("The season is probably summer.");
- }
- else if (temp >= 70 && temp < 90)
- {
- System.out.println("The season is probably spring.");
- }
- else if (temp >= 50 && temp < 70)
- {
- System.out.println("The season is probably autumn.");
- }
- else if (temp <50 && temp >-5)
- {
- System.out.println("The season is probably winter.");
- }
- else
- {
- System.out.println("The temperature you entered is outside the valid range.");
- }
- }
- }
- Program that outputs a year:
- package com.Suarez;
- /*
- Xander fermier
- 1/16/19
- the user inputs either two or four numbers and the computer will output that as a year
- */
- import java.util.*;
- public class YearOutput {
- public static void main( String [] args)
- {
- System.out.println("Give me a year");
- Scanner yearInput = new Scanner(System.in);
- String yearString = yearInput.next();
- int yearInt = Integer.parseInt(yearString);
- int yearLength = yearString.length();
- if (yearLength == 2)
- {
- System.out.println("The year is " + (yearInt + 2000));
- }
- else if(yearLength == 4)
- {
- System.out.println("The year is " + yearInt);
- }
- else
- {
- System.out.println("That is not a valid year.");
- }
- }
- }
- program that checks username and password:
- package com.Suarez;
- /*
- Xander Fermier
- 1/16/19
- the code takes a username and password from the user and then will grant or deny access depending on what they enter and tell them which filed did not match
- */
- import java.util.*;
- public class UsernameAndPasswordCheck {
- public static void main(String[] args)
- {
- System.out.println("Please enter your username.");
- Scanner input = new Scanner(System.in);
- String username = input.next();
- System.out.println("Enter your password");
- String password = input.next();
- if (username.equals("admin") && password.equals("open"))
- {
- System.out.println("Welcome.");
- }
- else if (username.equals("admin") && !password.equals("open"))
- {
- System.out.println("Wrong password.");
- }
- else if (!username.equals("admin") && password.equals("open"))
- {
- System.out.println("Wrong username.");
- }
- else
- {
- System.out.println("Sorry, wrong username and password.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement