Java | JSP | JSF Answers

Questions: 3 611

Answers by our 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 & Filtering

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.


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.


Construct a class called Rectangle. A Rectangle has both a length and a width (both positive integers). Access to them should be only inside the class and within the inheritance hierarchy. Then implement the following:

  • lone constructor that accepts two integers for the length and the width. Prints "Rectangle Constructor"
  • getters and setters
  • area - prints "Rectangle Area" and returns the area of the rectangle
  • perimeter - prints "Rectangle Perimeter" and returns the perimeter of the rectangle


Square construction prints "Square Constructor" and accepts one integer which is the length of a side. The version of the area and perimeter of Square prints "Square Area" and "Square Perimeter", respectively.

Input

A positive integer representing the length of the side of a Square.

2

Output

The message of the constructors when called, the area, and perimeter of Square.

Rectangle·Constructor
Square·Constructor
Square·Area
Area:·4
Square·Perimeter
Perimeter:·8






LATEST TUTORIALS
APPROVED BY CLIENTS