Java | JSP | JSF Answers

Questions: 4 418

Answers by our Experts: 3 943

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 & Filtering

Create a class called Rational for performing arithmetic with fractions. Write a driver program to test your class.



Use integer variables to represent the private data of the class—the numerator and the denominator. Provide a constructor function that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case no initializers are provided and should store the fraction in reduced form



Provide public member functions for each of the



following:



a) Addition of two Rational numbers. The result should be stored in reduced form.



b) Subtraction of two Rational numbers. The result should be stored in reduced form.



c) Multiplication of two Rational numbers. The result should be stored in reduced form.



d) Division of two Rational numbers. The result should be stored in reduced form.



e) Printing Rational numbers in the form a/b where a is the numerator and b is the denominator. in java

Question 20 (10 points)

Write the Java code required to solve the following problem. A complete program is

required and must follow all programming conventions (indenting, variable names,

comments, etc...).

You are to create a program which will place 8 queens on a chess board.

1 - Create a blank chessboard (8 x8 2D array of integers, all O's)

2 - Using a loop, ask the user for 8 locations on the board, replace the O with a 1 at.

this location.

3 - Display the final board.

You do not need to include any error checking or checking for duplicate locations.


Suppose there is XYZ Company and there are different departments like production, marketing, finance, sales etc. Manager of the company want to know about the detail of the employees who are highly paid in each of the department. Write a program using the concept of classes to implement the same.


Develop a Java program for a lottery winning game. The secret win number is “980-6578-854-976”. The user is allowed to enter their try, up to 10 times. For any incorrect entry, the program displays “Sorry. Try Again.” For each wrong entry, the program displays number of attempts remaining. When the 10 attempts are over, it displays “You have exhausted your chances to win. Bye.” The user can also press “E” to opt out of the game any time during the attempts. If they enter the win number at any point, the program displays “CONGRATULATIONS!! YOU HAVE WON 6 MILLION KSHS.” Then allows the user to enter their name, IDNO and phone number, after which the program displays e.g. “John Kamau, IDNO 89765, Phone Number 07863539, we shall contact you on information on how to receive your price. Have a good day”.


Create a class named Square which performs the following tasks. a. Provide a method which returns calcuated area and circumference of the square and takes side length as one parameter of type integer. Write a test application named SquareApp which performs the following tasks. a. Create an object for the class Square. b. Read the side length of the Square from the user c. Pass the side length to the methods of the square class as an argument and print the calculated area and circumference of the square.


Write a program to take a String as input then display the words in one column, its length in another column, replace the first with last character of each word in third column.

Enter a String

a is the first vowel

a 1 a

is 2 si

the 3 eht

first 5 tirsf

vowel 5 lowev

Hint: Use length(), indexOf(), substring() if required.

Array & split are not to be used


In a particular factory, the team leader is an hourly paid production worker that leads a small team. In addition to hourly pay, team leaders earn a fixed monthly bonus. Team leaders are required to attend a minimum number of hours of training per year. Design a TeamLeader class that extends the Production Worker Class. The LeamLeader class should have fields for the monthly bonus amount, the required number of training hours, and the number of training hours that the team leader has attended. Write one or more constructors and the appropriate accessor and mutator methods for the class. Demo the class by using a program that uses the TeamLeader object. 


Create a class named INVOICE that contains fields for an item number, name, quantity, price, and total cost. Create instance methods that set the item name, quantity, and price. Whenever the price or quantity is set , recalculate the total (price times quantity ). Also include a DISPLAYLine() method that displays the item number, name, quantity, price for each INVOICE. Save the class as INVOICE.java


Sample output

item # : 111

Item name: chips

Quantity:2

Price: 1.00

Total Cost: 2.00


Name your database using your names as: “db_first_last_studentNumber”. ∙ Name all your tables in your database using this format: “tbl_tableName”. ∙   

∙ This mini-project is worth 20 marks (10 marks for a working GUI, 10 marks for performing CRUD  operations on a DB through the GUI). 

Milestone: 

For this unit, you are required to develop a GUI application using Java. The application  should connect to a database and should be able to perform any CRUD operation. 

Main goal:  

Develop a Java application with GUI for a primary school called Duka. 

Functional Requirements: 

The application should allow:  

i. A shop attendant to be able to login to upload stock of items (with prices). ii. A buyer be able to search for items, get their prices and make an order. 

Non-functional Requirements: 

The application should: 

i. Have a user-friendly GUI for both shop attendant and buyer. 

ii. Not crash in case a user makes a mistake, instead it should provide a  clarification/warning.





Given the following code, what is the value of ticTacToe[2].length

String row1[] = {" ","X","O"};

String row2[] = {"X"," ","O"};

String row3[] = {"O","X"," "};

String ticTacToe[][] = {row1,row2,row3};


LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS