Dek-D.com ใช้คุกกี้เพื่อพัฒนาประสบการณ์ของ
ผู้ใช้ให้ดียิ่งขึ้น เรียนรู้เพิ่มเติมที่นี่
ยอมรับ

โปรแกรมตัดเกรด ภาษาจาวา

ตั้งกระทู้ใหม่
ตั้งกระทู้ใหม่

import

java.util.Scanner;

class

{

life

public

{

Scanner scan=

static void main(String args[])new Scanner(System.in);

System

.out.println("Please input your Name : ");

String

name = scan.next();

System

.out.println("Please input your learn : ");

String

learn = scan.next();

System

.out.println("Please input your score : ");

double

s= scan.nextDouble();

System

.out.println("Please input your Name : "+name);

System

.out.println("Please input your learn : "+learn);

System

 

.out.println("Please input your score : "+s);

if

{

(s>100)

System

}

.out.println("Error please enter only 1-100");

else

{

if(s>79)

System

}

.out.println("Grade A");

else

{

if(s>69)

System

}

.out.println("Grade B");

else

{

if(s>59)

System

}

.out.println("Grade C");

else

{

if(s>49)

System

}

.out.println("Grade D");

else

{

if(s<50)

System

}

}

}

.out.println("Grade E");

แสดงความคิดเห็น

>

6 ความคิดเห็น

Over Clock 3 ธ.ค. 51 เวลา 23:40 น. 2

อันนี้แบบยาก

*** ส่วนของคาส MainStudent
import java.io.*;
public class MainStudent
{
&nbsp&nbsp&nbsp public static void main(String args[])throws IOException
&nbsp&nbsp&nbsp {
&nbsp&nbsp&nbsp MainStudent me = new MainStudent();
&nbsp&nbsp&nbsp me.run();
&nbsp&nbsp&nbsp }
&nbsp&nbsp&nbsp public void run()throws IOException
&nbsp&nbsp&nbsp {
&nbsp&nbsp&nbsp Student e1 = new Student();
&nbsp&nbsp&nbsp BufferedReader Stu = new BufferedReader(new InputStreamReader(System.in));
&nbsp&nbsp&nbsp 
&nbsp&nbsp&nbsp System.out.print("Name : ");
&nbsp&nbsp&nbsp e1.setName(Stu.readLine());
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp System.out.print("Lname : ");
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp e1.setLname(Stu.readLine());
&nbsp&nbsp&nbsp 
&nbsp&nbsp&nbsp System.out.println("");
&nbsp&nbsp&nbsp System.out.println("=========================");
&nbsp&nbsp&nbsp System.out.println("| Score 1 || Work 30&nbsp &nbsp |");
&nbsp&nbsp&nbsp System.out.println("| Score 2 || Midterm 30 |");
&nbsp&nbsp&nbsp System.out.println("| Score 3 || Final 40&nbsp  |");
&nbsp&nbsp&nbsp System.out.println("=========================");
&nbsp&nbsp&nbsp System.out.println("");
&nbsp&nbsp&nbsp 
int i;
for( i=0;i<3;i++){&nbsp&nbsp&nbsp 
System.out.print("&nbsp Score " +(i+1)+ " >>> ");
double x=Double.parseDouble(Stu.readLine());
e1.setScore(i,x);
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp  }
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp System.out.println("");
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp System.out.println("=========================");&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp System.out.println("Name = "+e1.getName());
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp System.out.println("Lname = "+e1.getLname());
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp System.out.println("Total Score = "+e1.getTscore());
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp System.out.println("Grade = "+e1.Grade());
&nbsp&nbsp&nbsp }
}

-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

*** ส่วนของคาส Student
public class Student
{
&nbsp&nbsp&nbsp private String sName,sLname;
&nbsp&nbsp&nbsp private double sScore[]=new double [3],Total = 0;
&nbsp&nbsp&nbsp public char g;
&nbsp&nbsp&nbsp 
&nbsp&nbsp&nbsp public void setName(String fname)
&nbsp&nbsp&nbsp {&nbsp&nbsp&nbsp sName = fname;&nbsp&nbsp&nbsp }
&nbsp&nbsp&nbsp 
&nbsp&nbsp&nbsp public void setLname(String lname)
&nbsp&nbsp&nbsp {&nbsp&nbsp&nbsp sLname = lname;&nbsp&nbsp&nbsp }
&nbsp&nbsp&nbsp 
&nbsp&nbsp&nbsp public void setScore(int i,double x)
&nbsp&nbsp&nbsp {&nbsp&nbsp&nbsp sScore[i]=x;&nbsp&nbsp&nbsp Total=Total+x;&nbsp&nbsp&nbsp }
&nbsp&nbsp&nbsp 
&nbsp&nbsp&nbsp public char Grade()
&nbsp&nbsp&nbsp {
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp if(Total<50)
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp g='F';
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp if(Total>=50)
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp g='D';
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp if(Total>=60)
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp g='C';
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp if(Total>=70)
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp g='B';
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp if(Total>=80)
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp g='A';
&nbsp&nbsp&nbsp &nbsp&nbsp&nbsp return g;&nbsp&nbsp&nbsp 
&nbsp&nbsp&nbsp }
&nbsp&nbsp&nbsp public String getName()
&nbsp&nbsp&nbsp {&nbsp&nbsp&nbsp return sName;&nbsp&nbsp&nbsp }
&nbsp&nbsp&nbsp public String getLname()
&nbsp&nbsp&nbsp {&nbsp&nbsp&nbsp return sLname;&nbsp&nbsp&nbsp }
&nbsp&nbsp&nbsp public double getTscore()
&nbsp&nbsp&nbsp {&nbsp&nbsp&nbsp return Total;&nbsp&nbsp&nbsp }
}

0