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

Write a program that models a snail ranch, as follows.

+REPRODUCTION_RATE : int = 100 {readOnly}
+BASE_POPULATION : int = 200 {readOnly}
-population : int

+SnailRanch(population : int)
+getPopulation() : int
+breed() : void
+harvest() : int

getPopulation() returns the current population, breed() causes the snails to breed
harvest() harvests the snails, returning the yield, the number of snails that could be harvested,
reducing the population to no lower than BASE POPULATION

REPRODUCTION RATE is the number of children per pair of snails
BASE POPULATION is the number of snails to be left in the ranch after a harvest, population is the current population of the ranch
SnailRanch(int) is a constructor that establishes a ranch with an initial population

Implement a Main class that reads a file of events and prints the events, the current
population after each event, and after all events have occurred, prints the total yield from the ranch.The name of the file of events will be supplied as a command line argument.

if the file txt contains these events:
stock 100
breed
breed
harvest
breed
harvest

then a run of the program would look like this:
$ java Main log.txt
stock 100
breed 5100
breed 260100
harvest 200
breed 10200
harvest 200
total yield = 269900
$
The first event will always be "stock" with the initial population of the ranch.
One acre of land is equivalent to 43,560 square feet. Write a program called land_calculation.js that calculates the number of acres in the a tract of land based on the total square feet in a tract of land. Use a literal value of 348,480 for the total square feet.
This is a UML class diagram using Java syntax for the members. It is a summary of the design. The full details will follow.
AccountNumber
private int[] digits
public AccountNumber(boolean random)
public String toString()
public static AccountNumber fromString(String number)
private int checksum()

This version uses UML syntax for the members.
AccountNumber
-digits : int[]
+AccountNumber(random : boolean)
+toString() : String
+fromString(number : String) : AccountNumber
-checksum() : int

Fields
private int[] digits

Constructors
public AccountNumber(boolean random)

Methods
public String toString()
public static AccountNumber fromString(String number)
private int checksum()

Implement AccountNumber.checksum() and the constructor and test it with a program that generates random, valid account numbers. Use a command line argument to specify how many numbers to generate, as follows:
$javaGenerate 2(2 lines)
24568231
13789425
Each class must have private instance fields that store the specific shapes dimensions.
Each class must have a constructor that supplies the dimensions.
Each class must have an area() function.
Each class must have a toString() function that returns strings like these, as appropriate:
∗ triangle (base = 1.00, height = 2.00)
∗ rectangle (width = 1.00, height = 1.00)
∗ square (side = 1.00)
∗ circle (radius = 1.00)
All numbers are rounded to two decimal places.

Write a Main class that works like this:
$ java Main
?triangle 1.0 2.0
Area of triangle (base = 1.00, height = 2.00) = 1.00
? rectangle 1.0 2.0
Area of rectangle (width = 1.00, height = 2.00) = 2.00
? square 1.0
Area of square (side = 1.00) = 1.00
? circle 1.0
Area of circle (radius = 1.00) = 3.14
? quit
$

It does not need to handle bad user input.
Hint: Your Main class will be simpler if you exploit inclusion polymorphism. Have a single variable
of type Shape, instead of many variables with different types.
I have to create a class that represents a rectangle. A rectangle is specified by the coordinates (x; y) of its top-left corner and its width and height.
This class will be used to create many rectangle objects, and it must feature:
{ dynamic fields (variables) to store x, y, the width and the height as fractional numbers;
{ a constructor with parameters that provide x, y, the width and the height;
{ a function that returns the area of the rectangle;
{ a function that returns the length of the perimeter of the rectangle; and
{ a function that returns a string representation of the rectangle, the four numbers, within a pair
of parentheses, separated by commas. This function must be named toString().

Write, in a separate Main class, a main method that accepts the four numbers as command line
arguments, instantiates a rectangle object, and prints the string representation of the rectangle, the area and the perimeter.
I have to write a program that accepts two command line string arguments and prints the lesser of them, if case is ignored. The program should look like this when it runs:
$
java Main Zoophyte aardvark
aardvark
$

This is the code I have so far:
public class LeastString {

public static void main (String[] args) {
String s = args[0];
String t = args[1];
System.out.println(s.trim());
System.out.println(t.trim());
System.out.println(s.compareToIgnoreCase(t));
if (s > t) {
System.out.println(s);
} else (s < t){
System.out.println(t);
}
}
}
what is a generic class???can u provide a simple demo program??
Im learning Java through the codingbat website. Im working on problem http://codingbat.com/prob/p121193
I have coded:
if (str.length() == 0) return 0;
int sum=0;
int start = 0;
int stop=0;
int f=0;
int j=0;
for (int i=0;i<str.length()-1;i++){
if (Character.isDigit(str.charAt(i))){
start = i;
if (i == str.length()-1) stop = i;
for (j=i+1 ;j < str.length()-1;j++){
if (!Character.isDigit(str.charAt(j))){
i = j;
stop = j;
j = j+ str.length();}
else {stop = j;}
}
sum += Integer.parseInt(str.substring(start,stop));
}
}
return sum;
}
This code passes a few of the tests. When value "aa11b33" enters the program and "start" (i) = 5, the "for" loop should start at j=6. In trying to figure out whats wrong, I commented out the "sum+=...." code and returned "stop". It returns a result of 4. Looking for advice on why this is happening. Thanks in advance NB
In the Byteland country a string "S" is said to super ascii string if and only if count of each character in the string is equal to its ascii value.
In the Byteland country ascii code of 'a' is 1, 'b' is 2 ...'z' is 26.
Your task is to find out whether the given string is a super ascii string or not.
I need help debugging this program for calculating a persons tip:

public class calculatetip
{
public static void main(String[] args)
{
double mycheck = 29.95, yourcheck = 39.95, mytip, yourtip;
System.out.println("Tips are");
calctip(double mycheck);
System.out.printf("My tip should be at least %.2f\n", tip);
calctip(double yourcheck);
System.out.printf("Your tip should be at least %.2f\n", tip);
}

public static void calctip()
{
double tip;
tip = bill * .20;
return tip;
}
}
LATEST TUTORIALS
APPROVED BY CLIENTS