Home / Expert Answers / Computer Science / source-code-and-pictures-below-for-implementations-and-requirements-please-help-i-will-upvote-witho-pa905

(Solved): Source code and pictures below for implementations and requirements. Please help I will upvote witho ...



Source code and pictures below for implementations and requirements. Please help I will upvote without hesitation.
Your job for this project is to provide the implementation for the Number class.
You can find the documentation for its publi
Sample Run of The Program
\( 123+987 \)
1110
\( 123 * 1111111111111111111111111111111111111 \)
136666666666666666666666666666hunisis
Almphareriesinkricces:
Derpuzenduchumeara
v.l?e elasa Mrebez
?e: ?ide tifimi.
\( 4.44 \) ix r?zasalsti as a Lins: ruPaiatstera:
auzer-a slrine erpenaline if tis auabe
This?:
Bulleunteknoz-ien- if auxe is ndlimport java.util.Scanner;


/**
 * <p>This program performs numerical calculations based on user's input.
 * An operation needs to be provided using a three-token format: 
 *    operand1  operator  operand2  
 * in which the three tokens are separated by one of more white spaces. 
 * The program terminates when the end of file (EOF) character is found. 
 * (Note, this character is entered in the console by typing Ctrl+D sequence.) 
 * 
 * <p>Valid operands are any positive integers (no length limit). 
 * 
 * <p>Valid operators are:
 * <pre>
 *  +   addition
 *  *   multiplication
 *  <   less than 
 *  <=  less than or equal
 *  >   greater than
 *  >=  greater than or equal 
 *  ==  equal
 *  <>  not equal 
 * </pre>
 */

public class LongNumbers {

	public static void main(String[] args) {
		
		
		Scanner in = new Scanner (System.in);
		
		String line = null;
		String[] tokens; 
		Number n1=null, n2=null, n3=null;
		
		while (in.hasNextLine() ) {
			//read input from user and break it into expected three tokens:
			//  operand1  operator  operand2 
			line = in.nextLine();
			tokens = line.split("\\s+"); 
			try {
				//get two operands 
				n1 = new Number(tokens[0]);
				n2 = new Number(tokens[2]);
				//perform the action of the operator 
				switch (tokens[1]) {
				case "+": 
					n3 = n1.add(n2); 
					System.out.println(n3);
					break;
				case "*": 
					n3 = n1.multiply(n2); 
					System.out.println(n3);
					break; 
				case "==":
					System.out.println(n1.equals(n2)  ? "true" : "false"); 
					break;
				case "<": 
					System.out.println(n1.compareTo(n2) < 0  ? "true" : "false"); 
					break;
				case "<=": 
					System.out.println(n1.compareTo(n2) <= 0  ? "true" : "false"); 
					break;
				case ">": 
					System.out.println(n1.compareTo(n2) > 0  ? "true" : "false"); 
					break;
				case ">=": 
					System.out.println(n1.compareTo(n2) >= 0  ? "true" : "false"); 
					break;
				case "<>": 
					System.out.println(n1.compareTo(n2) != 0  ? "true" : "false"); 
					break;
					
					
				default: //deals with unsupported and illegal operators 
					System.out.println("Illegal operator found: " + line);
					continue; 
				}
			}
			catch (IllegalArgumentException ex) {  //deals with illegal and misformatted requests 
				System.out.println("Illegal expression found: " + line);
				continue;
			}
			catch (ArrayIndexOutOfBoundsException ex) { //deals with illegal and misformatted requests 
				System.out.println("Illegal expression found: " + line);
				continue;
			}
		
		}
		
		in.close();
		
	}
	//prevent class instantiation (otherwise compiler generates default constructor) 
	private LongNumbers( ) {
		
	}

}
Your job for this project is to provide the implementation for the Number class. You can find the documentation for its public methods here. Requirements and restrictions - The class has to use a linked list to represent the object. In fact, Number is a linked list. You can implement it as a singly linked list of nodes that contain single digits. You can use dummy nodes at the start and end of the list, if you wish (but this is not something we discussed in class). - The class should have an internal private Node class. - You are not allowed to use any kind of List implementation provided by Java libraries. - You are not allowed to use the BigInteger class provided by Java Libraries. - All manipulations required to implement addition, multiplication and comparisons have to be performed on nodes of the list. (You cannot convert the objects to their integer or string equivalents and perform the operations on int, Integer or on characters of a string.) Any kind of numerical computations have to be performed on single digits only (although in some cases the result may have more than one digit). In order to implement the addition and multiplication you should recall the methods of performing these operations by hand (or long hand operations). If you do not remember how to do this, here are some tutorials: - Long Hand Addition - Long Hand Multiplication (There are many others you can find online.) Hint: the function multiplyBydigit ( ) in the Number class may come in handy in implementing the general multiply operation. DATA STORAGE AND ORGANIZATION You do not need to implement any other classes, but you may if you wish. PROGRAMMING RULES - You should follow the rules outlined in the document code conventions posted on the course website. - You may not use any of the collection classes provided in Java libraries. Do not use LinkedList, stack, Queue, or any classes implementing the List or queue interfaces). - You may not use the Biginteger class. - You may use any exception-related classes. Sample Run of The Program 1110 136666666666666666666666666666666666653 100000000000000011111111111111111111111111111111110 true false true false 366666666666666666663 Illegal expression found: Illegal expression found: 1000000000000000 - 999999999999999 Illegal operator found: hunisis Almphareriesinkricces: Derpuzenduchumear'a v.l?e elasa Mrebez ?e: ?ide tifimi. ix r?zasalsti as a Lins: ruke lid: Paiatstera: auzer-a slrine erpenaline if tis auabe This?: Bulleunteknoz-ien- if auxe is ndl


We have an Answer from Expert

View Expert Answer

Expert Answer


We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe