学生题 请理解 千万别喷我
第一道:
Java Exercise 3Create a class NumberWordFormat that has a ff. methods:public String format(int);
public int parse(String);E.g.format(1234) will return "one thousand two hundred thirty four"
format(1456879) will return "one million four hundred fifty six thousand eight hundred seventy nine"
format(0) will return "zero"
format(-13) will return "negative thirteen"
parse("one hundred eleven") will return 111
parse("two thousand four") will return 2004
parse("negative nine") will return -9
第二道:
Java Exercise 1Implement the ff. class hierarchy:Shape
Circle
Polygon
Triangle
Quadrilateral
Parallelogram
Rectangle
Rhombus
SquareYou should determine by yourself which classes and methods should be abstract.
Shape has the ff. methods:public double getArea();
public double getPerimeter();
public String getName(); - returns the name of the polygon based on the number of sides. (3 - triangle, 4 - quadrilateral, 5 - pentagon, 6 - hexagon, 7 - heptagon, 8 - octagon, 9 - nonagon, 10 - decagon, n-sided polygon), or circle, ellipse.Polygon should have the ff. methods:public int getNumberOfSides();
public int getTotalAngle();The total angle of a polygon is computed as:
(一个函数,这个 我自己来 嘿嘿~~)where n is the number of sides of a polygon.Create a class InvalidShapeException that extends from java.lang.Exception. The class should have a constructor that accepts a String. All shapes constructors will throw this Exception class if the parameter(s) is/are invalid, such as passing 0 or negative values as length of radius/sides/angles. Valid angles will be 0.0 < angle <= 90.0.
Circle should have a constructor that accepts a double value, which is the radius. The circumference (or perimeter) is computed as:
(一个函数,这个 我自己来 嘿嘿~~)And the area is computed as:(一个函数,这个 我自己来 嘿嘿~~)where r is the radius of the circle.Triangle should have a constructor that accepts 3 double values representing the 3 sides (all sides should be > 0.0), and the length of the longest side should be less than the sum of the other two sides. The area of a triangle is computed as:(一个函数,这个 我自己来 嘿嘿~~)
where
(一个函数,这个 我自己来 嘿嘿~~)a, b, and c are the three sides.The triangle should also have methods to determine if it's an equilateral, isosceles or scalene triangle. [boolean isEquilateral(), boolean isIsosceles(), boolean isScalene()]An equilateral triangle is a triangle where all sides are equal.
An isosceles triangle is a triangle where only 2 sides are equal.
A scalene triangle is a triangle where no 2 sides are equal.Class Parallelogram extends from Quadrilateral. The constructor accepts the length of 2 sides, the 1st is the base, and 2nd is a side. The 3rd parameter is the angle in degress between the base and the side.The area is computed as:(一个函数,这个 我自己来 嘿嘿~~)
Class Rhombus extends from Parallelogram. The constructor accepts a double value representing the length of it's sides, and an angle in degrees. A rhombus is a special parallelogram whose base and side are equal.Constructor of Rectangle should accept 2 double, indicating the width and height. A rectangle is actually a special parallelogram whose angle is 90 degrees.Constructor of Square should accept 1 double value, indicating the length of the sides. A square is a special rhombus whose angle is 90 degrees.
Write a main program where the user is asked to select a shape (Circle, Triangle, Rectangle, Square, Parallelogram, Rhombus), ask for the necessary parameters to create the shape, and output the area and perimeter/circumference. The output should be formatted to include a comma as thousand separator and rounded to 2 decimal digits.Bonus:Implement a class RegularPolygon, which extends from Polygon. The constructor will accept a double value representing the length of the side, and an int value representing the # of sides. The number of sides should be >= 3. The area of a regular polygon is computed as:(一个函数,这个 我自己来 嘿嘿~~)
where(一个函数,这个 我自己来 嘿嘿~~)
where s is the length of the side, n is the number of sides, and totalangle is the total angle of the polygon.Implement the class Ellipse, extends from shape, whose constructor accepts 2 double values a and b, representing the major radius and minor radius of the ellipse (a > b). Change the Circle class to extend from Ellipse.The area of an ellipse is computed as:(一个函数,这个 我自己来 嘿嘿~~)
An approximate formula for the circumference is:
(一个函数,这个 我自己来 嘿嘿~~)where (一个函数,这个 我自己来 嘿嘿~~)
第一道:
Java Exercise 3Create a class NumberWordFormat that has a ff. methods:public String format(int);
public int parse(String);E.g.format(1234) will return "one thousand two hundred thirty four"
format(1456879) will return "one million four hundred fifty six thousand eight hundred seventy nine"
format(0) will return "zero"
format(-13) will return "negative thirteen"
parse("one hundred eleven") will return 111
parse("two thousand four") will return 2004
parse("negative nine") will return -9
第二道:
Java Exercise 1Implement the ff. class hierarchy:Shape
Circle
Polygon
Triangle
Quadrilateral
Parallelogram
Rectangle
Rhombus
SquareYou should determine by yourself which classes and methods should be abstract.
Shape has the ff. methods:public double getArea();
public double getPerimeter();
public String getName(); - returns the name of the polygon based on the number of sides. (3 - triangle, 4 - quadrilateral, 5 - pentagon, 6 - hexagon, 7 - heptagon, 8 - octagon, 9 - nonagon, 10 - decagon, n-sided polygon), or circle, ellipse.Polygon should have the ff. methods:public int getNumberOfSides();
public int getTotalAngle();The total angle of a polygon is computed as:
(一个函数,这个 我自己来 嘿嘿~~)where n is the number of sides of a polygon.Create a class InvalidShapeException that extends from java.lang.Exception. The class should have a constructor that accepts a String. All shapes constructors will throw this Exception class if the parameter(s) is/are invalid, such as passing 0 or negative values as length of radius/sides/angles. Valid angles will be 0.0 < angle <= 90.0.
Circle should have a constructor that accepts a double value, which is the radius. The circumference (or perimeter) is computed as:
(一个函数,这个 我自己来 嘿嘿~~)And the area is computed as:(一个函数,这个 我自己来 嘿嘿~~)where r is the radius of the circle.Triangle should have a constructor that accepts 3 double values representing the 3 sides (all sides should be > 0.0), and the length of the longest side should be less than the sum of the other two sides. The area of a triangle is computed as:(一个函数,这个 我自己来 嘿嘿~~)
where
(一个函数,这个 我自己来 嘿嘿~~)a, b, and c are the three sides.The triangle should also have methods to determine if it's an equilateral, isosceles or scalene triangle. [boolean isEquilateral(), boolean isIsosceles(), boolean isScalene()]An equilateral triangle is a triangle where all sides are equal.
An isosceles triangle is a triangle where only 2 sides are equal.
A scalene triangle is a triangle where no 2 sides are equal.Class Parallelogram extends from Quadrilateral. The constructor accepts the length of 2 sides, the 1st is the base, and 2nd is a side. The 3rd parameter is the angle in degress between the base and the side.The area is computed as:(一个函数,这个 我自己来 嘿嘿~~)
Class Rhombus extends from Parallelogram. The constructor accepts a double value representing the length of it's sides, and an angle in degrees. A rhombus is a special parallelogram whose base and side are equal.Constructor of Rectangle should accept 2 double, indicating the width and height. A rectangle is actually a special parallelogram whose angle is 90 degrees.Constructor of Square should accept 1 double value, indicating the length of the sides. A square is a special rhombus whose angle is 90 degrees.
Write a main program where the user is asked to select a shape (Circle, Triangle, Rectangle, Square, Parallelogram, Rhombus), ask for the necessary parameters to create the shape, and output the area and perimeter/circumference. The output should be formatted to include a comma as thousand separator and rounded to 2 decimal digits.Bonus:Implement a class RegularPolygon, which extends from Polygon. The constructor will accept a double value representing the length of the side, and an int value representing the # of sides. The number of sides should be >= 3. The area of a regular polygon is computed as:(一个函数,这个 我自己来 嘿嘿~~)
where(一个函数,这个 我自己来 嘿嘿~~)
where s is the length of the side, n is the number of sides, and totalangle is the total angle of the polygon.Implement the class Ellipse, extends from shape, whose constructor accepts 2 double values a and b, representing the major radius and minor radius of the ellipse (a > b). Change the Circle class to extend from Ellipse.The area of an ellipse is computed as:(一个函数,这个 我自己来 嘿嘿~~)
An approximate formula for the circumference is:
(一个函数,这个 我自己来 嘿嘿~~)where (一个函数,这个 我自己来 嘿嘿~~)
解决方案 »
- 大批量 并发测试
- 菜鸟的SSH问题:查询条件被自动换成了问号,导致没有查出结果,恳请指点!
- Hibernate插入与删除数据的问题
- Error:java.lang.ClassCastException: org.hibernate.validator.event.ValidateEventListener
- weblogic做客户端调用webservice问题
- TOMCAT抛读取.hbm.xml文件问题出错!!!!
- 请教hibernate的blob和clob问题。
- 请问java如何调用.net 的 WEB SERVICE
- [HELP]Almost killed by Apache & Tomcat...
- 复选框树状结构
- response.encodeRedirectURL的问题
- jms中消息过滤的问题
public static void main(String[] args) {
System.out.println("please input a string....");
Scanner s = new Scanner(System.in);
String string = new String();
string = s.next();
if(string.indexOf("-")==0){
System.out.print("negavite"+" ");
string=string.substring(1, string.length());
}
TestMath t = new TestMath();
int n = string.length();
//当输入的为0时
if(n==1){
if(string.charAt(0)==48){
System.out.print("zero");
}
}
for(int i = 0 ;i<string.length();i++){
int k = string.charAt(i)-48;
if(n==2){
if(k==1){
int mm = Integer.parseInt(string.substring(string.length()-2, string.length()));
t.TestString(mm);
break;
}else{
t.Test2(k);
}
}else if(n==5){
if(k==1){
int mm = Integer.parseInt(string.substring(2, 4));
t.TestString(mm);
}else{
t.Test2(k);
}
}else{
if(k==0){
if(n==4)
System.out.print("thousand"+" ");
}else{
t.TestMath(k);
t.Test(n);
}
}
n--;
}
}
//个位数字
public void TestMath(int k){
switch (k) {
case 1:
System.out.print("one"+" ");
break;
case 2:
System.out.print("two"+" ");
break;
case 3:
System.out.print("three"+" ");
break;
case 4:
System.out.print("four"+" ");
break;
case 5:
System.out.print("five"+" ");
break;
case 6:
System.out.print("six"+" ");
break;
case 7:
System.out.print("server"+" ");
break;
case 8:
System.out.print("eight"+" ");
break;
case 9:
System.out.print("nine"+" ");
break;
case 0:
System.out.print("zero"+" ");
break;
default:
break;
}
}
//十位数字
public void Test2(int m){
switch (m) {
case 2:
System.out.print("twoty"+" ");
break;
case 3:
System.out.print("threety"+" ");
break;
case 4:
System.out.print("fourty"+" ");
break;
case 5:
System.out.print("fivety"+" ");
break;
case 6:
System.out.print("sixty"+" ");
break;
case 7:
System.out.print("serverty"+" ");
break;
case 8:
System.out.print("eightty"+" ");
break;
case 9:
System.out.print("ninety"+" ");
break;
case 0:
System.out.print("");
break;
default:
break;
}
}
//最后2位数字
public void TestString(int m){
switch (m) {
case 11:
System.out.print("eleven"+" ");
break;
case 12:
System.out.print("twnteen"+" ");
break;
case 13:
System.out.print("thrity"+" ");
break;
case 14:
System.out.print("fourteen"+" ");
break;
case 15:
System.out.print("fiveteen"+" ");
break;
case 16:
System.out.print("sixteen"+" ");
break;
case 17:
System.out.print("serverteen"+" ");
break;
case 18:
System.out.print("eightteen"+" ");
break;
case 19:
System.out.print("nineteen"+" ");
break;
case 10:
System.out.print("twnty"+" ");
break;
default:
break;
}
}
//数字的单位
public void Test(int j){
switch (j) {
case 3:
System.out.print("handred"+" ");
break;
case 4:
System.out.print("thousand"+" ");
break;
case 6:
System.out.print("hundred"+" ");
break;
case 7:
System.out.print("million"+" ");
break;
default:
break;
}
}
}