Java:
Do NOT use: Math, Integer, Character or StringBuilder classes to complete these methods.
Code
public class BasicJava4 {
public static boolean isAlphabetic(char aChar)
{
return (aChar >= 'a' && aChar <= 'z') || (aChar >=
'A' && aChar <= 'Z');
}
public static int round(double num)
{
int roundedNum=(int)num;
if(num%1>=0.5)
roundedNum+=1;
return roundedNum;
}
public static boolean useSameChars(String str1, String str2)
{
boolean found;
for(int i=0;i<str1.length();i++)
{
found=false;
for(int j=0;j<str2.length();j++)
{
if(str1.charAt(i)==str2.charAt(j))
{
found=true;
break;
}
}
if(!found)
return false;
}
return true;
}
public static int reverse(int num)
{
int reverseNum=0;
int rem;
while(num>0)
{
rem=num%10;
num/=10;
reverseNum=reverseNum*10+rem;
}
return reverseNum;
}
public static void main(String[] args)
{
//test isAlphabetic function.
System.out.println("Testing isAlphabetic function");
System.out.println("a isAlphabetic: "+isAlphabetic('a'));
System.out.println("H isAlphabetic: "+isAlphabetic('H'));
System.out.println("9 isAlphabetic: "+isAlphabetic('9'));
//test round function.
System.out.println("\nTesting round function");
System.out.println("2.6 round to : "+round(2.6));
System.out.println("2.3 round to : "+round(2.3));
//test useSameChars function.
System.out.println("\nTesting useSameChars function");
System.out.println("hello whim and mellow him uses same chacters :
"+useSameChars("hello whim","mellow him"));
System.out.println("zim whim and mellow him uses same chacters :
"+useSameChars("zim whim","mellow him"));
//test reveese function.
System.out.println("\nTesting reveese function");
System.out.println("49386 in revese is "+reverse(49386));
System.out.println("1234 in revese is "+reverse(1234));
}
}
all the function are in bold
output
If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.
Java: Create the skeleton. Create a new file called ‘BasicJava4.java’ Create a class in the file...
/* * CPS150_Lab10.java */ import java.io.*; import java.util.*; /** * CPS 150, Fall 2018 semester * * Section N1 * * Lab Project 13: Comparing Java Strings * * @author *** Replace with your name *** */ public class CPS150_Lab13 { static final Scanner KBD = new Scanner(System.in); static final PrintStream OUT = System.out; // TO DO: Implement each of the following 4 methods, // using the String compareTo method: /* * lessThan(String, String) -> boolean * * method is...
Problem 1 1. In the src → edu.neiu.p2 → problem1 directory, create a Java class called HW4P1 and add the following: • The main method. Leave the main method empty for now. • Create a method named xyzPeriod that takes a String as a parameter and returns a boolean. • Return true if the String parameter contains the sequential characters xyz, and false otherwise. However, a period is never allowed to immediately precede (i.e. come before) the sequential characters xyz....
I have a Graph.java which I need to complete four methods in the java file: completeGraph(), valence(int vid), DFS(int start), and findPathBFS(int start, int end). I also have a JUnit test file GraphTest.java for you to check your code. Here is Graph.java: import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; import java.util.Stack; /* Generic vertex class */ class Vertex<T> { public T data; public boolean visited; public Vertex() { data = null; visited = false; } public Vertex(T _data) { data =...
please answer question (5 points) Below is the skeleton for a simplified StringBuilder class as done in the Closed Lab this semester. As in the lab, the class has an ArrayList of Character to hold the individual characters of the StringBuilder object. Write the instance method indexOf as given below that returns the index of the first occurrence of the character c in the SimplestringBuilder. If there is no index for that character (i.e. the character is not in the...
Create a method based program to find if a number is prime and then print all the prime numbers from 1 through 500 Method Name: isPrime(int num) and returns a boolean Use for loop to capture all the prime numbers (1 through 500) Create a file to add the list of prime numbers Working Files: public class IsPrimeMethod { public static void main(String[] args) { String input; // To hold keyboard input String message; // Message...
Required in Java. Thank you. 1. Create a base class called Vehicle that has the manufacturer's name (type String), number of cylinders in the engine (type int), and owner (type Person given in Listing 8.1 in the textbook and in LMS). Then create a class called Truck that is derived from Vehicle and has additional properties: the load capacity in tons (type double, since it may contain a fractional part) and towing capacity in tons (type double). Give your classes...
*JAVA* Can somebody take a look at my current challenge? I need to throw a different exception when a)(b is entered. It should throw "Correct number of parenthesis but incorrect syntax" The code is as follows. Stack class: public class ArrayStack<E> { private int top, size; private E arrS[]; private static final int MAX_STACK_SIZE = 10; public ArrayStack() { this.arrS = (E[]) new Object[MAX_STACK_SIZE]; this.top = size; this.size = 0;...
Can someone help me out with this? You are given a program that receives four lines in the below format, and stores them in str1, str2, str3, and num1. This is not a very long sentence. is long 4 Expand this program to: Write an if-elseif-else statement to print this line only if num1 is higher than 0: "Num1 is higher than 0!" print this line only if num1 is 0: "Num1 equals to 0!" And otherwise, print: ""Num1 is...
Why am I getting compile errors. rowPuzzle.java:9: error: class, interface, or enum expected public static boolean rowPuzzle(ArrayList<Integer> squares, int index, ArrayList<Boolean> visited) ^ rowPuzzle.java:16: error: class, interface, or enum expected } //Java Program import java.util.*; // rowPuzzle helper function implementation // File: rowPuzzle.cpp // Header files section // function prototypes public static boolean rowPuzzle(ArrayList<Integer> squares, int index, ArrayList<Boolean> visited) { // base case // return true if the puzzle is solvable if (index == squares.size() - 1) { return...
Please help me do the java project For this project you will be reading in a text file and evaluating it in order to create a new file that represents the Class that will represent the properties of the text file. For example, consider the following text file: students.txt ID Name Age IsMale GPA 1 Tom Ryan 22 True 3.1 2 Jack Peterson 31 True 2.7 3 Cindy LuWho 12 False 3.9 When you read in the header line, you...