METHODS FIRST ASSIGNMENT (EVEN AND ODD CHECKR)

Temperature Q2

import java.util.Scanner;
public class Temperature {
static void validation(Scanner input){
while(!input.hasNextInt()) {
System.out.println("YOU have enter a letter where a number is
expected");
System.out.println("Please try again");
input.next();
}
}
static int celsius(int a){
int d = a + 32;
return d * 9/5;
}
static int fahr(int a ){
int d = a -32;
return d * 5/9;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("============================================");
System.out.println(" TEMPERATURE CONVERTER");
System.out.println("=============================================");
System.out.println(" ");
System.out.println("Enter the number or the value of the temperature
you wish to convert");
validation(input);
int numberEntered = input.nextInt();
int choose;
do {
System.out.println("Which of the two would you like to do your
conversion to");
System.out.println("1: TO CELSIUS (C)");
System.out.println("2: TO FAHRENHEIT (F)");
System.out.println("3: EXIT");
System.out.print("Choose an option : ");
validation(input);
choose= input.nextInt();
switch (choose){
case 1:
System.out.println( numberEntered +" to celsius is: "+
celsius(numberEntered));
break;
case 2:
System.out.println( numberEntered +" to celsius is:
"+fahr(numberEntered));
break;
}
}while (choose != 3);
}
}





Even_odd_checker Q1


import java.util.*;
public class Even_odd_checker {
static boolean evenandodd(int a ) {
return a % 2 == 0;
}
static void validation(Scanner input){
while (!input.hasNextInt()){
System.out.println("You have enter a number where a letter is
expected ");
System.out.println("Please try again");
input.next();
}
}
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
System.out.println("=========================================");
System.out.println(" EVEN AND ODD CALCULATOR");
System.out.println("=========================================");
System.out.println(" ");
System.out.println("Enter the number you wish to determine if it's an
odd or even number");
validation(input);
int number = input.nextInt();
System.out.println(evenandodd(number));
if (evenandodd(number) ==true){
System.out.println("The number "+ number +" is an EVEN number");
}else {
System.out.println("The number "+ number +" is an ODD number");
}
}
}

Leapyear Q3


import java.util.Scanner;
public class leapyear {
static void leapYear(int a){
if (a % 400 ==0){
System.out.println(a+" is a leap year");
}else {
System.out.println(a+ " is not a leap year");
}
}
static void validation(Scanner input){
while (!input.hasNextInt()){
System.out.println("You have enter a letter where a number is
expected ");
System.out.println("Please try again");
input.next();
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("=========================================");
System.out.println(" LEAP AND NON-LEAP DETERMINANT");
System.out.println("==========================================");
System.out.println(" ");
System.out.println("Enter the year you wish to check ");
validation(input);
int yearEntered = input.nextInt();
leapYear(yearEntered);
}
}
calculateScore Q4
import java.util.*;
class calculate {
String name;
int scores;
public int calculateScore(String playerName, int score){
playerName = name;
System.out.println("The player name: "+playerName);
System.out.println(" ");
System.out.println( playerName+" has a score of: "+score);
System.out.println("==================");
return score;
}
public int calculateScore(int score){
System.out.println("Player Name : Unknown" );
System.out.println(" ");
calculateScore(name,score);
System.out.println("========================");
return score;
}
static int calculateScore(){
System.out.println("No player name or score was provided");
return 0;
}
static void validation(Scanner input){
while (!input.hasNext()){
System.out.println("YOU have enter a number where a letter is
expected");
System.out.println("Please try again");
input.next();
}
}
static void validations(Scanner input){
while (!input.hasNextInt()){
System.out.println("YOU have enter a number where a letter is
expected");
System.out.println("Please try again");
input.next();
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("===========================================");
System.out.println(" PLAYER SCORE CHECKER");
System.out.println("============================================");
System.out.println(" ");
System.out.println("Enter a player name");
validation(input);
String player = input.nextLine();
System.out.println(" ");
System.out.println("Enter the player score");
validations(input);
int score = input.nextInt();
calculate player1 = new calculate();
player1.name = player;
player1.scores = score;
player1.calculateScore(player,score);
player1.calculateScore(score);
calculateScore();
}
}




MZ232 Q6
import java.util.Scanner;
public class MZ232 {
static int calArea(int a, int b){
return a * b;
}
static double calArea(int a){
return a*a;
}
static double calcarea(int c){
return Math.PI*c*c;
}
static void validation(Scanner input){
while (!input.hasNextInt()){
System.out.println("You have enter a number a letter is
expecteds");
System.out.println("Please try again");
input.next();
}
}
static void selection(){
System.out.println("choos the shape the client desire");
System.out.println("1: Square");
System.out.println("2: Rectangle");
System.out.println("3: Circle");
}
static void number(){
System.out.println("Enter the size needed by the client");
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("===========================");
System.out.println(" MZ232 Company");
System.out.println("============================");
System.out.println(" ");
selection();
validation(input);
int shapeSelection = input.nextInt();
switch (shapeSelection){
case 1:
number();
validation(input);
int needed1 = input.nextInt();
System.out.println(calArea(needed1));
break;
case 2:
System.out.println("Enter the length size needed by the
client ");
validation(input);
int needed2 = input.nextInt();
System.out.println("Enter the width size needed by the
client");
validation(input);
int needed3 = input.nextInt();
System.out.println(calArea(needed2,needed3));
break;
case 3:
System.out.println("Enter the size of the radius needed by
the client");
validation(input);
int needed4 = input.nextInt();
System.out.println(calcarea(needed4));
break;
}
}
}


Summer Q5

import java.util.Scanner;
class DogPlay {
static void summer(){
System.out.println("Choose one of the questions below to determine
inorder to proceed");
System.out.println("1: SUMMER");
System.out.println("2: Not Summer");
System.out.println(" ");
}
static void validation(Scanner input){
while (!input.hasNextInt()){
System.out.println("You have enter a number where a letter is
expected");
System.out.println("Try again");
input.next();
}
}
static void playing(Scanner input) {
summer();
validation(input);
int summer = input.nextInt();
switch (summer){
case 1:
System.out.println("It is summer");
System.out.println("Enter the temperature");
validation(input);
int temperature = input.nextInt();
if (temperature >= 25 && temperature <= 45){
System.out.println("true");
}else {
System.out.println("false");
}
break;
case 2:
System.out.println("It's not summer");
System.out.println("Enter the temperature");
validation(input);
int temp = input.nextInt();
if (temp >25 && temp <30){
System.out.println("true");
}else {
System.out.println("false");
}
break;
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("====================================");
System.out.println(" DOG PLAYING");
System.out.println("=====================================");
playing(input);
}
}









Comments

Popular posts from this blog

Computer programming Assignment.

Calculatior

leap year