Java Programming

Homework:

Prompt the user for an Integer and one of the following Strings: convert, add, or subtract.

If the user enters “convert” or “Convert”, multiply the number entered by 5 then divide the result by 9.If the user enters “add” or “Add”, add 15.8549 to the number. If the user enters “subtract” or “Subtract”, subtract 1.0001 from the number then square the result.

Display the result with at most two places after the decimal point. Include the function chosen in the printout.

If anything other than convert, add, or subtract is entered print an error message and stop.

5.24 Lab7Num3

Write a program that accepts a word from the keyboard (a string) and converts it into Pig Latin. Output the word in Pig Latin. These are the rules for conversion: Look at the first character in the word, if it is a vowel, just add “way” to the end of the word Otherwise move the consonant to the end and add “ay”. For example: “apple” becomes “appleway” and “cat” becomes “atcay”

import java.util.Scanner;

public class Lab7Num3 {

public static void main(String[] args) {

Scanner keyboard = new Scanner (System.in);

//get phrase

System.out.println(“Enter a word in lowercase”);

}

}

5.23 Lab7Num2

Suppose you work for an online service that provides a bulletin board for its users. You would like to filter out profanity and consider the words “cat”, “dog”, “llama” to be profane. Write a program that reads a phrase from the keyboard and tests whether the string contains one of these words. Output “contains profanity” or “doesn’t contain profanity”. If the input is: “I have a dog” your program should output “contains profanity”.

import java.util.Scanner;

public class Lab7Num2 {

public static void main(String[] args) {

Scanner keyboard = new Scanner (System.in);

String str;

System.out.println(“Enter a phrase”);

if ()

System.out.println(“contains profanity”);

else

System.out.println(“does not contain profanity”);

}

}

5.22 Lab7Num1

An integer is divisible by another if the remainder after division is zero. For example, 10 % 5 is zero, but 7 % 5 is not. Write a program that accepts two integers from the keyboard and outputs whether the first one is divisible by the second.

import java.util.Scanner;

public class Lab7Num1 {

public static void main(String[] args) {

Scanner keyboard = new Scanner (System.in);

int num1;

int num2;

System.out.println(“Enter two integers”);

if()

System.out.println(num1 + ” is divisible by ” + num2);

else

System.out.println(num1 + ” is not divisible by ” + num2);

}

}

Needs help with similar assignment?

We are available 24x7 to deliver the best services and assignment ready within 3-4 hours? Order a custom-written, plagiarism-free paper

Order Over WhatsApp Place an Order Online

Do you have an upcoming essay or assignment due?

All of our assignments are originally produced, unique, and free of plagiarism.

If yes Order Similar Paper