下面是我做好的功课,老师说我里面出问题...但又不肯解释到底那出问题.....请各位帮我看看因该如何改正,可以的话因该如何完善他呢??谢谢 /*
* Main.java
*
* Java application
*
* Created on 27-09-2008 20:16 PM
*/
import java.io.*;
public class Main
{
public static void main(String args[]) throws Exception {
java.io.BufferedReader buf;
buf = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
System.out.print("Enter the first number:");
int x = Integer.parseInt(buf.readLine()); java.io.BufferedReader buf1;
buf1=new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
System.out.print("Please enter an operator(+,-,*,/):");
String operator = buf1.readLine(); java.io.BufferedReader buf2;
buf2 = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
System.out.print("Enter the second number:");
int y = Integer.parseInt(buf2.readLine());
if (operator.equals("+")){System.out.print(x+"+"+y+"="+(x+=y));}
if (operator.equals("-")){System.out.print(x+"-"+y+"="+(x-=y));}
if (operator.equals("*")){System.out.print(x+"*"+y+"="+(x*=y));}
if (operator.equals("/"))
{if(y==0){
System.out.print("Error!Divisor cannot be ZERO");}
if(y!=0)
{System.out.print(x+"/"+y+"="+(x/=y));}
if (operator.equals("#")){System.out.print("Error!Invalid operator'#'");}
}
}
}/*
* Main.java
*
* Main Java application
*
* Created on 28-09-2008 02:17 PM
*/import java.text.*;
import java.io.*;
import java.lang.*;class Ball{
//attribute
double radius;
String name;
//constructor
public Ball(){
radius = 0;
name = "";
}
public Ball(double r,String n){
radius = r;
name = n;
}
//method getRadius
public double getRadius() {
return radius;
}
//method getName
public String getName() {
return name;
}
//method bigball
public void bigball(){
radius =2;
}
//method smallball
public void smallball(){
radius =1;
}
//method Basketball
public void Basketball(){
name = "basketball";
}
}
public class Main{
public static void main(String[] args) throws IOException{
Ball a1;
a1 = new Ball(2 ,"basketball");
a1.getRadius();
a1.getName();
a1.bigball();
a1.Basketball();
Ball a2;
a2 = new Ball(1,"football");
a2.getRadius();
a2.getName();
a2.smallball();
}
}
* Main.java
*
* Java application
*
* Created on 27-09-2008 20:16 PM
*/
import java.io.*;
public class Main
{
public static void main(String args[]) throws Exception {
java.io.BufferedReader buf;
buf = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
System.out.print("Enter the first number:");
int x = Integer.parseInt(buf.readLine()); java.io.BufferedReader buf1;
buf1=new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
System.out.print("Please enter an operator(+,-,*,/):");
String operator = buf1.readLine(); java.io.BufferedReader buf2;
buf2 = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
System.out.print("Enter the second number:");
int y = Integer.parseInt(buf2.readLine());
if (operator.equals("+")){System.out.print(x+"+"+y+"="+(x+=y));}
if (operator.equals("-")){System.out.print(x+"-"+y+"="+(x-=y));}
if (operator.equals("*")){System.out.print(x+"*"+y+"="+(x*=y));}
if (operator.equals("/"))
{if(y==0){
System.out.print("Error!Divisor cannot be ZERO");}
if(y!=0)
{System.out.print(x+"/"+y+"="+(x/=y));}
if (operator.equals("#")){System.out.print("Error!Invalid operator'#'");}
}
}
}/*
* Main.java
*
* Main Java application
*
* Created on 28-09-2008 02:17 PM
*/import java.text.*;
import java.io.*;
import java.lang.*;class Ball{
//attribute
double radius;
String name;
//constructor
public Ball(){
radius = 0;
name = "";
}
public Ball(double r,String n){
radius = r;
name = n;
}
//method getRadius
public double getRadius() {
return radius;
}
//method getName
public String getName() {
return name;
}
//method bigball
public void bigball(){
radius =2;
}
//method smallball
public void smallball(){
radius =1;
}
//method Basketball
public void Basketball(){
name = "basketball";
}
}
public class Main{
public static void main(String[] args) throws IOException{
Ball a1;
a1 = new Ball(2 ,"basketball");
a1.getRadius();
a1.getName();
a1.bigball();
a1.Basketball();
Ball a2;
a2 = new Ball(1,"football");
a2.getRadius();
a2.getName();
a2.smallball();
}
}
解决方案 »
- 我想实现一个流的输入输出,看书看了半天啦,东凑西凑凑出个程序,可是不能实现,5555555555555555,晕死了。谁能帮我看看
- 随着时间的增长增加数据
- java问题求解
- 难题,将JAVA绘制的图形输出JPEG文件,
- 关于JasperReport1.2.5和iReport1.2.5如何制作饼图,柱图等图形图表。。。。急。。。。
- 怎么判断出每一年中的春节是那一天?
- 正则问题。
- 《大哥、大姐帮帮忙》怎样将一张图片按一定宽度和高度进行分割成多个图片??
- 请大家帮忙,怎样判断字符串内部有没有空格,并能去掉它们?
- 怎麼樣在Panel上顯示一個圖片?
- java流怎么close最合适
- 关于一个JAVA程序占用CPU的问题
Main是java中保留字段是不能够做类名的,请楼主以后一定要注意类名的设置.而且,提醒楼主,对于第一个题目中你已经把io包导入进来了,为什么还java.io.BufferedReader,这样不麻烦吗?还有对第二个题目中,你的
a1.bigball();
a1.Basketball(); a2.smallball();
豪无意义,因为你在a1,a2初始化时就已经设置为相应的属性了,还请楼主仔细考虑!
1 类名可以是Main 没关系
2 你既然是三个类,就别把类名重复了,至少叫 Main1 Main2 也好啊!
3 Ball 类,你有get方法,为何没有对应的set方法呢? 也许不需要,这个倒没啥关系。
4 你的加减乘除的代码,唯一要注意的,就是如果用户没有输入数字,或者根本啥也没输入就按了回车,你要进行异常处理,然后用户再次输入。
顶 ,另外在main方法还使用throws是很不厚道的做法哦,呵呵