HW # 1 Posted on: Tuesday, January 12, 2016 8:00:00 PM EST This HW is based on p
ID: 3662867 • Letter: H
Question
HW # 1
Posted on: Tuesday, January 12, 2016 8:00:00 PM EST
This HW is based on programming projects (PPs) # 1 and # 3 from Chapter 5 (p. 371 & p. 372) of your text.
Use the following list of scores for 10 students.
Student ID
Quiz # 1
Quiz # 2
Midterm Exam
Final Exam
A1
8
8.5
84
82
B2
3
7
0
99
C3
10
9.5
92
84
D4
8
8
89
86
E5
9
10
83
91
F6
7.5
8.5
88
69
G7
8.5
0
81
52
H8
6
8.5
79
68
I9
7.5
6
72
91
J10
7
6.5
58
77
1. Put the above data in a text file with 10 rows of data. Each row has 5 elements as depicted above. Name the file “scores.txt.”
2. Instantiate a "ClassGrade" object; update the object as the file is being read, line-by-line.
3. Use the grading policy described in PP # 1 to determine the following: a) the highest score for Quiz # 1, b) the lowest score for Quiz # 2, c) midterm average, and d) final letter grades for all students.
4. Remember this is an OOP assignment; not a procedural programming HW.
5. Submit your source code and the input data in email.
Pg. 371
Pg. 372
HW # 1
Posted on: Tuesday, January 12, 2016 8:00:00 PM EST
This HW is based on programming projects (PPs) # 1 and # 3 from Chapter 5 (p. 371 & p. 372) of your text.
Use the following list of scores for 10 students.
Student ID
Quiz # 1
Quiz # 2
Midterm Exam
Final Exam
A1
8
8.5
84
82
B2
3
7
0
99
C3
10
9.5
92
84
D4
8
8
89
86
E5
9
10
83
91
F6
7.5
8.5
88
69
G7
8.5
0
81
52
H8
6
8.5
79
68
I9
7.5
6
72
91
J10
7
6.5
58
77
1. Put the above data in a text file with 10 rows of data. Each row has 5 elements as depicted above. Name the file “scores.txt.”
2. Instantiate a "ClassGrade" object; update the object as the file is being read, line-by-line.
3. Use the grading policy described in PP # 1 to determine the following: a) the highest score for Quiz # 1, b) the lowest score for Quiz # 2, c) midterm average, and d) final letter grades for all students.
4. Remember this is an OOP assignment; not a procedural programming HW.
5. Submit your source code and the input data in email.
Pg. 371
Pg. 372
Please use java:
import java.util.ArrayList;
import java.io.*;
public class ClassGrade {
private ArrayList<Student> theClass;
private ClassGrade readFile;
public ClassGrade() {
this.theClass = new ArrayList<Student>();
}
public void readFile() {
//1. Inside a try/catch block, set up our BufferedReader
//2. Set up a loop that will read the file until no lines are available
//3. Inside that loop, read one line, split it into parts, and use the Student constructor to create a new Student
//4. Add that student to the ArrayList.
try {
BufferedReader br = new BufferedReader(new FileReader("scores.txt"));
String ourLine;
while((ourLine = br.readLine()) != null) {
String[] separatedLine = ourLine.split(" ");
Student newStudent = new Student(separatedLine[0],Double.parseDouble(separatedLine[1]),Double.parseDouble(separatedLine[2]),Double.parseDouble(separatedLine[3]),Double.parseDouble(separatedLine[4]));
this.theClass.add(newStudent);
}
br.close();
}
catch(IOException e) {
e.printStackTrace();
}
}
public Student highestQuiz1() {
double currentMax = -1;
Student bestStudent = this.theClass.get(0);
for(int i = 0 ; i < this.theClass.size() ; i++) {
if(this.theClass.get(i).getquiz1() >= currentMax) {
currentMax = theClass.get(i).getquiz1();
bestStudent = theClass.get(i);
}
}
return bestStudent;
}
public Student lowestQuiz2() {
double currentMin = 1000;
Student worstStudent = this.theClass.get(0);
for(int i = 0 ; i < this.theClass.size() ; i++) {
if(theClass.get(i).getquiz1() <= currentMin) {
currentMin = theClass.get(i).getquiz2();
worstStudent = theClass.get(i);
}
}
return worstStudent;
}
public double getMidtermAverage() {
double average = 0;
for(int i = 0 ; i < this.theClass.size() ; i++) {
average += this.theClass.get(i).getmidterm();
}
return average / this.theClass.size();
}
public void finalLetterGrades() {
for(int i = 0 ; i < this.theClass.size() ; i++) {
String line = this.theClass.get(i).getID() + " : ";
double finalGrade = this.theClass.get(i).getfinal()*0.5 + this.theClass.get(i).getmidterm()*0.25 + (this.theClass.get(i).getquiz1()/10 + this.theClass.get(i).getquiz2()/10)*0.25;
if(finalGrade<60) line += "F";
else if(finalGrade<70) line += "D";
else if(finalGrade<80) line += "C";
else if(finalGrade<90) line += "B";
else line += "A";
System.out.println(line + " " + finalGrade);
}
}
public static void main(String[] args) {
ClassGrade grades = new ClassGrade();
grades.setReadFile(new ClassGrade());
System.out.println("The highest score in Quiz 1 is :"
+ grades.highestQuiz1().getquiz1() + " out of 10 points,"
+ " or " + grades.highestQuiz1().getquiz1() / 10 * 100 +"%");
System.out.println("The lowest score in Quiz 2 is :" + grades.lowestQuiz2().getquiz2() + " out of 10 points, or " + grades.lowestQuiz2().getquiz2() / 10 * 100 +"%");
System.out.println("The midterm average is: "+grades.getMidtermAverage()+"%");
System.out.println("The final grades are:");
grades.finalLetterGrades();
}
public ClassGrade getReadFile() {
return readFile;
}
public void setReadFile(ClassGrade readFile) {
this.readFile = readFile;
}
}
public class Student {
private String studentID;
private double quiz1,quiz2,midterm,finalGrade;
public Student(String ID, double Q1, double Q2, double mid, double fin){
this.studentID = ID;
this.quiz1 = Q1;
this.quiz2 = Q2;
this.midterm = mid;
this.finalGrade = fin;
}
public String getID() {
return this.studentID;
}
public double getquiz1(){
return this.quiz1;
}
public double getquiz2() {
return this.quiz2;
}
public double getmidterm() {
return this.midterm;
}
public double getfinal() {
return this.finalGrade;
}
public void setStudentID(String ID) {
this.studentID = ID;
}
public void setquiz1(double quiz1) {
this.quiz1 = quiz1;
}
public void setquiz2(double quiz2){
this.quiz2 = quiz2;
}
public void setmidterm(double midterm){
this.midterm = midterm;
}
public void setfinal(double finalGrade){
this.finalGrade = finalGrade;
}
}
Student ID
Quiz # 1
Quiz # 2
Midterm Exam
Final Exam
A1
8
8.5
84
82
B2
3
7
0
99
C3
10
9.5
92
84
D4
8
8
89
86
E5
9
10
83
91
F6
7.5
8.5
88
69
G7
8.5
0
81
52
H8
6
8.5
79
68
I9
7.5
6
72
91
J10
7
6.5
58
77
Explanation / Answer
4. Write a program that uses purchase class in listing....
package inventory2;
import java.util.Scanner;
public class RunApp
{
public static void main(String[] args)
{
Scanner input = new Scanner( System.in );
Items theItem = new Items();
int number;
String Name = "";
System.out.print("How many items are to be put into inventory count?: ");
number = input.nextInt();
input.nextLine();
Items[]inv = new Items[number];
for(int count = 0; count < inv.length; ++count)
{
System.out.print(" What is item " +(count +1) + "'s name?: ");
Name = input.nextLine();
theItem.setName(Name);
System.out.print("Enter " + Name + "'s product number: ");
double pNumber = input.nextDouble();
theItem.setpNumber(pNumber);
System.out.print("How many " + Name + "s are there in inventory?: ");
double Units = input.nextDouble();
theItem.setUnits(Units);
System.out.print(Name + "'s cost: ");
double Price = input.nextDouble();
theItem.setPrice (Price);
inv[count] = new Items(Name, Price, Units, pNumber);
input.nextLine();
System.out.print(" Product Name: " + theItem.getName());
System.out.print(" Product Number: " + theItem.getpNumber());
System.out.print(" Amount of Units in Stock: " + theItem.getUnits());
System.out.print(" Price per Unit: " + theItem.getPrice() + " ");
System.out.printf(" Total cost for %s in stock: $%.2f", theItem.getName(), theItem.calculateTotalPrice());
System.out.printf("Total Cost for all items entered: $%.2f", theItem.calculateTotalPrice()); //i need to prompt for output to show total price for all items in array
}
}
}
public void setPrice(double p)
{
Price = p;
}
//getter methods
public String getName()
{
return Name;
}
public double getpNumber()
{
return pNumber;
}
public double getUnits()
{
return Units;
}
public double getPrice()
{
return Price;
}
public double calculateTotalPrice()
{
return (Units * Price);
}
public double calculateAllItemsTotalPrice() //i need method to calculate total cost for all items in array
{
return (TotalPrice );
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.