import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;/*
* @(#) CSI1100.java
* Created on 2004-10-4
* By James Fancy
*//**
* CSI1100
*
* @author James
*/
public class CSI1100 { int hours;
int minutes;
int seconds; public void printInfo() {
System.out.println("CSI1100 Fall 2004, Assignment 2, Question 1d)");
System.out.println("Name: Alan Williams, Student# 81069665");
System.out.println("Lab section 999, TA: Grace Hopper");
System.out.println();
} private int readInteger() throws IOException {
BufferedReader bis = new BufferedReader(
new InputStreamReader(System.in));
String line = bis.readLine();
try {
return Integer.parseInt(line);
} catch (NumberFormatException e) {
return 0;
}
} public void read() throws IOException {
System.out.print("Enter the value for hours:");
hours = readInteger();
System.out.print("Enter the value for minutes:");
minutes = readInteger();
System.out.print("Enter the value for seconds:");
seconds = readInteger();
System.out.println();
} public static void main(String[] args) throws IOException {
CSI1100 cst1100 = new CSI1100();
cst1100.printInfo();
cst1100.read();
System.out.print("This duration contains ");
System.out.print(new NumberOfSeconds(cst1100).getValue());
System.out.println(" seconds.");
} public static class NumberOfSeconds { long value; public NumberOfSeconds(CSI1100 csi) {
value = ((long) csi.hours) * 3600 + csi.minutes * 60 + csi.seconds;
} public long getValue() {
return value;
}
}}
import java.io.IOException;
import java.io.InputStreamReader;/*
* @(#) CSI1100.java
* Created on 2004-10-4
* By James Fancy
*//**
* CSI1100
*
* @author James
*/
public class CSI1100 { int hours;
int minutes;
int seconds; public void printInfo() {
System.out.println("CSI1100 Fall 2004, Assignment 2, Question 1d)");
System.out.println("Name: Alan Williams, Student# 81069665");
System.out.println("Lab section 999, TA: Grace Hopper");
System.out.println();
} private int readInteger() throws IOException {
BufferedReader bis = new BufferedReader(
new InputStreamReader(System.in));
String line = bis.readLine();
try {
return Integer.parseInt(line);
} catch (NumberFormatException e) {
return 0;
}
} public void read() throws IOException {
System.out.print("Enter the value for hours:");
hours = readInteger();
System.out.print("Enter the value for minutes:");
minutes = readInteger();
System.out.print("Enter the value for seconds:");
seconds = readInteger();
System.out.println();
} public static void main(String[] args) throws IOException {
CSI1100 cst1100 = new CSI1100();
cst1100.printInfo();
cst1100.read();
System.out.print("This duration contains ");
System.out.print(new NumberOfSeconds(cst1100).getValue());
System.out.println(" seconds.");
} public static class NumberOfSeconds { long value; public NumberOfSeconds(CSI1100 csi) {
value = ((long) csi.hours) * 3600 + csi.minutes * 60 + csi.seconds;
} public long getValue() {
return value;
}
}}
什么都不知道
还望以后大哥多加提点
QQ群:4187754Andrew1023(朱恩杰) 多编一些面向对象的程序,多看一些实例,思想慢慢就形成了。
题目本来就是一个时间转换来着。就是在输入输出的时候要做点文章。
jamsfancy 用了一个静态的类放在main()函数的下面,想法不错,写的比我要好的多了,
楼上大哥水平不赖哈!!
努力ing!
也就是大一的题
19212 % 3600 = 1212 秒
1212 / 60 = 20分钟
1212 % 60 = 12秒
这样算 5 小时 20 分钟 12 秒我觉得更好一些。
what is the assumption?