Java | JSP | JSF Answers

Questions answered by Experts: 3 611

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

Factorials


by CodeChum Admin



For those of you who may not now, a factorial is a product of multiplying from 1 until the number. Now, you must make a program that will accept an integer and then print out its factorial using loops.



Are you up for this task?





Instructions:



Input a positive integer.


Using a for() loop, generate the factorial value of the integer and print out the result.


Tip #1: Factorials work like this: Factorial of 5 = 1 * 2 * 3 * 4 * 5


Tip #2: There's a special case in factorials. The factorial of 0 is 1.


Input



A line containing an integer.



5


Output



A line containing an integer.



120

Visit any institution in Sierra Leone Government or Private and study their functions or services and develop a java console application that either overhaul or automate it. 

Implement the following java concept in your solution and highlight in your documentation or code where you did it:

1. Class and Object

2. File and Stream

3. Exception Handling 

 

Outcomes

 

On successful completion of this project, students will be able to:

● Analyse, design, and develop application using Java.

● Understand and implement some basic java concepts and principles.

● Identify real life problems and find technological solution to them.



develop a java console application that either overhaul or automate it.

Implement the following java concept in your solution and highlight in your documentation or code where you did it: and explain the steps

1. Class and Object

2. File and Stream

3. Exception Handling


Create a program that gets values as CMD args as follows, a person's name, year of birth and gender. The program then prints a message as follows:[HINT: if the person is male then the program uses Mr otherwise use Ms]

Sample 01:

Java Lab01_Task04 John 1999 M

Output

Good Mr John, you are 21 years old


  1. LOOPS&CONDITIONS: Create a program that takes in two numbers and then calculate the sum of all even numbers in between the two numbers. The program should also calculate the products of all the odd numbers between the provided numbers.

 

Sample run 1:                                                 

Enter two numbers: 2 8                                                

Output:

Even numbers: 2 4 6 8

Odd numbers: 3 5 7

Sum of even numbers = 20

Product of odd numbers = 105

Correct the code:-


public class DLL {

private Node start;

private Node end;

int count;


public DLL() {

start = end = null;

count=0;

}


public void insertAtstrat (Data d) {

if (count == 0) {

Node tn = new Node(d,null,null);

start = end = tn;

}


else {

Node tn = new Node (d,start,null);

start.prev = tn;

start (tn);

count++;

}

}

public void insertAtend (Data d) {

if (count == 0) {

insertAtend(d);

}

else {

Node tn = new Node(d,null,end);

end.next = tn;

end = tn;

count++;

}

public void insertAt(Data d, index i) {

if (count ==0 || index == 0);

insertAtstart(d);

else if (i >= count);

insertAtend(d);

else {

Node temp = start;

for (a = 1);

temp = temp.Node;

Node tn = new Node(d, temp.next, temp);

temp.next = tn;

temp = tn.next;

temp.prev = tn;

}

}

}

}


public class Node {

Data d;

Node next;

Node prev;

public Node (Data d,Node n,Node p) {

d = new Data();

next = n;

prev = p;

}



 Write a java program that specifies four parallel one dimensional arrays to store the product name, quantity and cost plus ItemTotal. Each array should be capable of holding a number elements provided by user input. Using a for loop input values for length and width arrays. The entries in the area arrays should be the corresponding values for the product, which is to be used to calculate the costs as follows (thus, itemTotat[i] =  quantity [i]* cost [i]) after data has been entered display the following receipt as output:

 

Sample Run1

Enter the number of products2

Enter product 1 name, Qty and CostBanana 4 2.65

Enter product 1 name, Qty and CostCoke 1 9.18

 

Output1:

Product         Quantity        Cost               Total

----------    -----------        -------      --------

Banana      4          2.65       10.60

coke              1          9.18       9.18

Sub-Total                         19.78

VAT(15%)                         2.97

TOTAL                                   N$        22.75


5. Prompt the user to enter y or n. If the user enters an invalid character, keep re-prompting until a value character is entered. Use a while loop.

 

6. Redo

for(int a=1; a<=3; a++)

  for(int b=2; b<5; b++)

   out.print(a+b + " ");

with a do-while loop.

 

7. Write a method checkeven which receives 3 integer variables and prints YES if all three numbers are even. Otherwise, the method prints NO. ("receives" means that these values will be passed to the method as parameters)


8. Write the statements to read in three numbers and call the checkeven method.


9. Write another version of the checkeven method. This version receives 3 integer variables and returns true if all three numbers are even. Otherwise, the method returns false.


10. Write the statements to read in three numbers and call the new version of the checkeven method. Then print YES if all three numbers were even, or print NO if they were not all even.



I'm quite into games now, so how about we play In or Out! When a given number is even, the team scores so we shall print "In", but if it's not an even number, then we print "Out". Simple, right?


Now let's get this game started.


Input

A line containing an integer.


35

Output

A line containing a string.


Out




You have to build 2 classes ExpenseItem, ExpenseLedger Class ExpenseLedger record expenses you make. You record expense by serial number,description,amount. Create a class ExpenseItem with serialnum, description,amount. Provide constructors, toString for this class. Now in ExpenseLedger class create arraylist of ExpenseItem. Provide following methods


void addExpense(description, amount). This method create an expense item and add it to ledger. Int removeSmallExpenses(double amt):This method will find expense items that are smaller or equal to amount amt and remove items from list. Note that multiple items can be smaller than this value and thus each of these should removed. Also this method should return number of items removed. Double totalExpenditure(): This method calculate total expenditure recorded in ledger so far. You can do this by iterating through expenses list and adding all the amounts to find the total expenditure so far. Override toString method so ledger is printed in well formatted way


LATEST TUTORIALS
APPROVED BY CLIENTS