今天解決了生理週期的計算問題,趕腳自己真心特別粗心,for循環裏面最開始居然寫錯了字母,然後好久都改不出bug,因爲l成了i,很像有木有!好吧,這不能作爲自己粗心的一萬個理由,嘿嘿,話不多說,等下還要看步步高電商的哥哥姐姐過來分享招人嘞,我先把題目奉上:
問題描述
人生來就有三個生理週期,分別爲體力、感情和智力週期,它們的週期長度爲23天、28 天和33 天。每一個週期中有一天是高峯。在高峯這天,人會在相應的方面表現出色。例如,智力週期的高峯,人會思維敏捷,精力容易高度集中。因爲三個週期的周長不同,所以通常三個週期的高峯不會落在同一天。對於每個人,我們想知道何時三個高峯落在同一天。
對於每個週期,我們會給出從當前年份的第一天開始,到出現高峯的天數(不一定是第一次高峯出現的時間)。你的任務是給定一個從當年第一天開始數的天數,輸出從給定時間開始(不包括給定時間)下一次三個高峯落在同一天的時間(距給定時間的天數)。例如:給定時間爲10,下次出現三個高峯同天的時間是12,則輸出2(注意這裏不是3)。
輸入數據
輸入四個整數:p,e, i 和d。 p, e, i 分別表示體力、情感和智力高峯出現的時間(時間從當年的第一天開始計算)。d是給定的時間,可能小於p,e, 或i。 所有給定時間是非負的並且小於365, 所求的時間小於等於21252。
輸出要求
從給定時間起,下一次三個高峯同天的時間(距離給定時間的天數)。
輸入樣例
0 0 0 0
0 0 0 100
5 20 34 325
4 5 6 7
283 102 23 320
203 301 203 40
-1 -1 -1 -1
輸出樣例
Case 1: the next triple peak occursin 21252 days.
Case 2: the next triple peak occursin 21152 days.
Case 3: the next triple peak occursin 19575 days.
Case 4: the next triple peak occursin 16994 days.
Case 5: the next triple peak occursin 8910 days.
Case 6: the next triple peak occursin 10789 days.
然後,我的代碼運行之後的結果是這樣滴,看下有木有比昨天的界面會好看一些……
然後以下就是俺今天上午敲的代碼:
import java.awt.Color;
import java.awt.Font;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class PeakP extends JFrame{
MyListener l;
public static void main(String[] args) {
PeakP pp=new PeakP();
pp.GUI();
}
public void GUI(){
this.setTitle("生 理 周 期");
this.setSize(700, 550);
this.setLocation(300, 50);
this.setDefaultCloseOperation(3);
this.setLayout(null);
JPanel jp1=new JPanel();
jp1.setBounds(0, 0, 200, 600);
jp1.setBackground(Color.white);
ImageIcon im3=new ImageIcon(this.getClass().getResource("3.jpg"));
this.setIconImage(im3.getImage());
ImageIcon im2=new ImageIcon(this.getClass().getResource("2.PNG"));
JLabel jl2 =new JLabel(im2);
jl2.setBounds(0, 20, im2.getIconWidth(), im2.getIconHeight());
jp1.add(jl2);
JPanel jp2=new JPanel();
jp2.setBounds(200,0,500,600);
jp2.setLayout(null);
ImageIcon im1=new ImageIcon(this.getClass().getResource("1.PNG"));
JLabel jl1 =new JLabel(im1);
jl1.setBounds(0, 5, im1.getIconWidth(), im1.getIconHeight());
jp2.add(jl1);
JLabel jl3=new JLabel("請輸入體力高峯的時間:");
jl3.setFont(new Font("楷體", 3, 18));
jl3.setBounds(10, 190, 230, 30);
JLabel jl4=new JLabel("請輸入情感高峯的時間:");
jl4.setFont(new Font("楷體", 3, 18));
jl4.setBounds(10, 240, 230, 30);
JLabel jl5=new JLabel("請輸入智商高峯的時間:");
jl5.setFont(new Font("楷體", 3, 18));
jl5.setBounds(10, 290, 230, 30);
JLabel jl6=new JLabel("請輸入你想給定的時間:");
jl6.setFont(new Font("楷體", 3, 18));
jl6.setBounds(10, 340, 230, 30);
JTextField jt1=new JTextField();
jt1.setFont(new Font("楷體", 2, 18));
jt1.setBounds(225, 190, 200, 30);
jt1.setHorizontalAlignment((int) CENTER_ALIGNMENT);
JTextField jt2=new JTextField();
jt2.setFont(new Font("楷體", 2, 18));
jt2.setBounds(225, 240, 200, 30);
jt2.setHorizontalAlignment((int) CENTER_ALIGNMENT);
JTextField jt3=new JTextField();
jt3.setFont(new Font("楷體", 2, 18));
jt3.setBounds(225, 290, 200, 30);
jt3.setHorizontalAlignment((int) CENTER_ALIGNMENT);
JTextField jt4=new JTextField();
jt4.setFont(new Font("楷體", 2, 18));
jt4.setBounds(225, 340, 200, 30);
jt4.setHorizontalAlignment((int) CENTER_ALIGNMENT);
JLabel jl7=new JLabel("結果:");
jl7.setBounds(10, 395,70, 20);
jl7.setFont(new Font("楷體", 3, 20));
JLabel jl8=new JLabel("");
jl8.setBounds(80, 395,350, 20);
jl8.setFont(new Font("楷體", 2, 16));
JButton jb1=new JButton("開始查詢");
jb1.setBounds(60, 440, 120, 40);
jb1.setFont(new Font("楷體", 1, 16));
JButton jb2=new JButton("重新查詢");
jb2.setBounds(250, 440, 120, 40);
jb2.setFont(new Font("楷體", 1, 16));
jp2.add(jl3);
jp2.add(jl4);
jp2.add(jl5);
jp2.add(jl6);
jp2.add(jl7);
jp2.add(jl8);
jp2.add(jb1);
jp2.add(jb2);
jp2.add(jt1);
jp2.add(jt2);
jp2.add(jt3);
jp2.add(jt4);
this.add(jp1);
this.add(jp2);
l=new MyListener(jt1,jt2,jt3,jt4,jl8,jb1,jb2);
jb1.addActionListener(l);
jb2.addActionListener(l);
this.setVisible(true);
}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class MyListener implements ActionListener{
JTextField jt[];
JButton jb1,jb2;
JLabel jl8;
int p[];
public MyListener(JTextField jt1,JTextField jt2,JTextField jt3,JTextField jt4,JLabel jl8,JButton jb1,JButton jb2){
jt=new JTextField[]{jt1,jt2,jt3,jt4};
this.jl8=jl8;
this.jb1=jb1;
this.jb2=jb2;
}
@Override
public void actionPerformed(ActionEvent e) {
int p[]=new int[]{0,0,0,0};
if(("開始查詢").equals(e.getActionCommand())){
for(int i=0;i<4;i++){
p[i]=Integer.parseInt(jt[i].getText());
}
draw(p[0],p[1],p[2],p[3]);
}
if(("重新查詢").equals(e.getActionCommand())){
for(int i=0;i<4;i++){
jt[i].setText("");
jl8.setText("");
}
}
}
public void draw(int p,int e,int i,int d){
int s=0;
for(int l=1;l<=22000;l++){
if((l-p)%23==0&&(l-e)%28==0&&(l-i)%33==0){
s=l-d;
break;
}
}
jl8.setText("the next triple peak occurs in "+s+" day.");
}
}
好啦,最近雖然沒有上什麼新內容,但是在做學校要求的習題的時候,感覺態度上改變了很多,很開心自己能輕鬆高興地面對這些,而不是像以前一樣皺着眉頭抄着夥伴的代碼……
還有就是總結下自己今天犯的坑爹錯,下次設變量的時候儘量不設長得像的字母,吃一塹長一智吧……
總之,有進步就是好事哈……麼麼噠!