대학생 코딩 과제 대행 java, python, oracle 열여덟 번째
https://open.kakao.com/o/s3aMpbA
이번에는 외국대학굔데 어디학굔지는 모른다.
java의 기초를 요구하는 과제였다.
요구사항은 아래에 문제가 총 3갠데 1번, 2번, 3번 중
2번 3번만 의뢰했다
실행영상을 찍기 귀찮기도 하고 영상으로 찍을것도 없어서 그냥 코드를 올린다.
class Book {
int id;
String author;
String title;
int noOfPages;
boolean fiction;
public Book(int id, String author, String title, int noOfPages, boolean fiction) {
this.id = id;
this.author = author;
this.title = title;
this.noOfPages = noOfPages;
this.fiction = fiction;
}
@Override
public String toString() {
return "id:" + id + ", Title:" + title + ", Author:" + author +
", No. of pages:" + noOfPages + ", Fiction:"
+ fiction;
}
}
public class BookStore {
public static void main(String[] args) {
Book[] books = new Book[10];
books[0] = new Book(10,"The Red Sari","Javier Moro",102,false);
books[1] = new Book(4,"Neither a Hake Nor a dove","Khurshid M Kasuari",350,true);
books[2] = new Book(1,"Faces and Places Professor","Deepak Nayyar,",311,false);
books[3] = new Book(6,"Indian Parliamentary Diplomacy","Meira Kumar",89,true);
books[4] = new Book(5,"Farishta,","Kapil Isapuari",600,false);
books[5] = new Book(3,"Super Economies","Raghav Bahal",201,true);
books[6] = new Book(2,"China :Confucius in the Shadow","Poonam Surie,",199,false);
books[7] = new Book(7,"My country My Life","L.K.Advani",143,false);
books[8] = new Book(9,"Joseph Anton","Sulman Rushdie",454,true);
books[9] = new Book(8,"A Political Biography","Andy Marino",411,false);
int fiction_cnt = 0;
int non_fiction_cnt =0;
int page_more_200 = 0;
int page_less_200 = 0;
for( int i = 0 ; i<books.length; i++){
System.out.println(books[i].toString());
System.out.println();
if(books[i].fiction == true)
fiction_cnt +=1;
else
non_fiction_cnt +=1;
if(books[i].noOfPages >= 200)
page_more_200 += 1;
if(books[i].noOfPages <= 200)
page_less_200 += 1;
}
System.out.println(page_more_200+" books have number of pages more than 200.");
System.out.println();
System.out.println(page_less_200+" books have number of pages less than 200.");
System.out.println();
System.out.println(fiction_cnt + " books are fiction.");
System.out.println();
System.out.println(non_fiction_cnt + " books are not fiction.");
}
}
public class Students {
private String courseName;
private int numberOfStudents;
private int[] points;
private char[] grades;
private char[] randomGrades;
public Students(String courseName, int numberOfStudents) {
this.courseName = courseName;
this.numberOfStudents = numberOfStudents;
this.grades = new char[numberOfStudents];
}
public void generatePoints(){
this.points = new int[this.numberOfStudents];
for ( int i =0; i<this.numberOfStudents; i++){
this.points[i] = (int)(Math.random()*50) + 50;
}
}
public void calculateGrades(){
for( int i =0; i<this.numberOfStudents; i++){
if (points[i] >=90)
grades[i] = 'A';
else if(points[i] >= 80 & points[i] <90)
grades[i] = 'B';
else if(points[i] >= 70 & points[i] <80)
grades[i] = 'C';
else if(points[i] >= 60 & points[i] <70)
grades[i] = 'D';
else if(points[i] >= 50 & points[i] <60)
grades[i] = 'E';
else if( points[i] < 50)
grades[i] = 'F';
}
// displayGrades();
}
private void displayGrades(){
System.out.println(this.courseName);
for(int i = 0; i<this.numberOfStudents; i++){
System.out.println("Student no.\t"+i+": Grade is\t"+this.grades[i]);
}
}
public void generateRandomGrades(){
this.randomGrades = new char[this.numberOfStudents];
for(int i =0 ; i<this.numberOfStudents; i++){
int random = (int)(Math.random() * 5) + 1;
if(random == 1)
randomGrades[i] = 'A';
else if (random == 2)
randomGrades[i] = 'B';
else if (random == 3)
randomGrades[i] = 'C';
else if (random == 4)
randomGrades[i] = 'D';
else if (random == 5)
randomGrades[i] = 'E';
else if (random == 6)
randomGrades[i] = 'F';
}
}
public void displayGradesDetails(){
String c = "correct";
String nc = "not correct";
int cnt = 0;
for(int i =0; i<this.numberOfStudents; i++){
if(grades[i] == randomGrades[i]){
System.out.println("Student no.\t"+i+": Grade is\t"+this.grades[i]
+" which is "+ c);
}
else{
System.out.println("Student no.\t"+i+": Grade is\t"+this.grades[i]
+" which is "+ nc);
cnt += 1;
}
}
System.out.println("Total "+ cnt+" students are wrongly graded");
}
public static void main(String[] args){
Students is147=new Students("Introduction to Java Programming",24);
is147.generatePoints();
is147.calculateGrades();
is147.generateRandomGrades();
is147.displayGradesDetails();
}
}
댓글
댓글 쓰기