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...
Java : Please help me correct my code: create a single class (Program11.java) with a main method and some auxiliary methods to input a 2-D array from a disk file, input some “transactions” to change the 2-D array and output the changed 2-D array to another file. Your main method will be minimal (see below). Most of the work will go on in your methods. In main, declare (but do not instantiate) 2-D array. Then call the three methods. The...
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...
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...
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 =...
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....
Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course { /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...
Create a class called CompareArrays that determines if two specified integer arrays are equal. The class should have one static methods: public static boolean compare(int[] arrayOne, int[] arrayTwo) – Which compares the two arrays for equality. The two arrays are considered equal if they are the same size, and contain the same elements in the same order. If they are equal, the method should return true. Otherwise, the method should return false. Create a second class called CompareArraysTest that contains...
containsSubSequence takes two Strings as input and returns a boolean: Returns true if the first input string contains all the characters of the second input string, in order, but not necessarily consecutively. > HW2.containsSubSequence("abracadabra", "abcd") true > HW2.containsSubSequence("abracadabra", "abdc") false you must not use either break or continue in your code. You are allowed to use the following methods from the Java API: class String length charAt class StringBuilder length charAt append toString class Character any method I write something...
Trying to figure out these methods for comp sci class and I really don't understand. Any help would be really appreciated. /** * */ public static int [] setNums(String vals) { //this is a helper method to convert a string to an array for searching purposes //declare and instantiate an array with length as the number of chars in vals //lopp through each char in vals ...