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

Write a program to take a String as input then display the words in spaced format.

Example:

Enter a String

Asia is the largest continent

Asia

\t is

\t \t the

\t \t \t largest

\t \t \t \t continent


You have to generate electricity bill for a customer with the details as give below: Customer ID, Customer Name, Customer Address, Contact No, Units Consumed, Total payable amount. Following are the norms to calculate the unit amount:



a) for initial 100 units it will cost 6 rupees per unit


b) for next 100 units it will cost 8 rupees per unit


c) for next all units it will cost 10 rupees per unit

Suppose you are planning to go to park so you are going to check tickets criteria online. The


ticket rates details have been given


*If children below 10 are not allowed to swing

*If age is between 10 to 15 allowed to swing and getting 10% discount

*If age is between 15 to 20 allowed to swing and getting 5% discount *If age is more than 20 not then not eligible for swing and discount


The age of person will run until you enter the age of last family member and then calculate the total charge amount after entering each person's age. Assume price of ticket is 100 Rs. each person.


Create class named PIZZA.


Data field include a string for toppings( such as pepperoni), an integer for diameter in inches (such as 12), and a double for price(such as as 23.70).


Include methods to get and set values for each of these fields.



B. Create an application name TESTPizza the instantiates one demonstrate the use of Pizza set and get methods. Save the application TestPizza.java

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

a)    Write a class called Square, as a subclass of Rectangle. Convince yourself that Square can be modeled as a subclass of Rectangle. Square has no instance variable, but inherits the instance variables width and length from its superclass Rectangle.

·        Provide the appropriate constructors (as shown in the class diagram). Hint:

public Square(double side) {

super(side, side); // Call superclass Rectangle(double, double)

}

·        Override the toString() method to return "A Square with side=xxx, which is a subclass of yyy", where yyy is the output of the toString() method from the superclass.

·        Do you need to override the getArea() and getPerimeter()? Try them out.

·        Override the setLength() and setWidth() to change both the width and length, so as to maintain the square geometry.



a)    The Rectangle class contains:

·        Two instance variables width (double) and length (double).

·        Three constructors as shown. The no-arg constructor initializes the width and length to 1.0.

·        Getter and setter for all the instance variables.

·        Methods getArea() and getPerimeter().

·        Override the inherited toString() method, to return "A Rectangle with width=xxx and length=zzz, which is a subclass of yyy", where yyy is the output of the toString() method from the superclass.




Write two subclasses of Shape called Circle and Rectangle, as shown in the class diagram.

a)    The Circle class contains:

·        An instance variable radius (double).

·        Three constructors as shown. The no-arg constructor initializes the radius to 1.0.

·        Getter and setter for the instance variable radius.

·        Methods getArea() and getPerimeter().

·        Override the inherited toString() method, to return "A Circle with radius=xxx, which is a subclass of yyy", where yyy is the output of the toString() method from the superclass.



This assignment has 4 sub-sections.

Use the JOptionPane class for all required input/output.

 

a)    Write a superclass called Shape (as shown in the class diagram), which contains:

·        Two instance variables color (String) and filled (boolean).

·        Two constructors: a no-arg (no-argument) constructor that initializes the color to "green" and filled to true, and a constructor that initializes the color and filled to the given values.

·        Getter and setter for all the instance variables. By convention, the getter for a boolean variable xxx is called isXXX() (instead of getXxx() for all the other types).

·        A toString() method that returns "A Shape with color of xxx and filled/Not filled".

Write a test program to test all the methods defined in Shape.




int i,l,p=0,j; char c; String s,w="",r="";

System.out.println("Enter a String");

s = sc.nextLine(); s = s.trim()+" "; l = s.length();

for (i=0;i<l;i++) {

c = s.charAt(i);

if (c != 32) 

w = w + c;

else { p++;

for (j=w.length()-1;j>=0;j--) {

c = w.charAt(j); r = r + c;

} if (w.compareToIgnoreCase(r) == 0 && r.length() > 1) 

System.out.println(w+"\t"+p);

w = ""; r = "";

}

if (i == l-1) {

p++;

for (j=w.length()-1;j>=0;j--) {

c = w.charAt(j);

r = r + c;

}

if (w.compareToIgnoreCase(r) == 0 && r.length() > 1)

System.out.println(w+"\t"+p); }}}}

Q. Above coding will display palindrome words along with its position that is where it is present in the String. Add a statement to above coding so that it will display ''No palindrome words found" if there is not a single palindrome word present in the entered String.


LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS