Question
please use java

1. Modify the Student class presented to you as follows. Each student object should also contain the scores for three tests.
public class Firm 11- // Creates a staff of employees for a firm and pays them //----- public static void main(String[] args)
public class Staff private StaffMember [] staffList; //-------------------- // Constructor: Sets up the list of staff members
staffList[0] = new Executive (Sam, 123 Main Line, 555-0469, 123-45-6789, 2423.07); staffList[1] = new Employee (Carl
1/ Represents a college student. // *** * *** ** ** *************** * * ** public class Student private String firstName, las

do what u can
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 1:

Student.java

public class Student {

   private int testOneScore;
   private int testTwoScore;
   private int testThreeScore;

   public Student(int testOneScore, int testTwoScore, int testThreeScore) {
       super();
       this.testOneScore = testOneScore;
       this.testTwoScore = testTwoScore;
       this.testThreeScore = testThreeScore;
   }

   public Student() {
       this.testOneScore = 0;
       this.testTwoScore = 0;
       this.testThreeScore = 0;
   }

   public void setTestScore(int testNumber, int score) {
       if (testNumber == 1) {
           this.testOneScore = score;
       } else if (testNumber == 2) {
           this.testTwoScore = score;
       } else {
           this.testThreeScore = score;
       }
   }

   public int getTestScore(int testNumber) {
       if (testNumber == 1) {
           return this.testOneScore;
       } else if (testNumber == 2) {
           return this.testTwoScore;
       }
       return this.testThreeScore;
   }

   public int average() {
       return (this.testOneScore + this.testTwoScore + this.testThreeScore) / 3;
   }

   @Override
   public String toString() {
       return "Test One Score: " + this.testOneScore + " Test Two Score: " + this.testTwoScore + " Test Three Score: "
               + this.testThreeScore + " Avarage: " + average();
   }

}
Driver class StudentApp.java

public class StudentApp {

   public static void main(String[] args) {
       Student student1 = new Student(30, 35, 40);
      
       System.out.println("-------------Student1-----------");
       System.out.println("Test Score 2: "+student1.getTestScore(2));
       System.out.println("Average is: "+student1.average());
       System.out.println(student1);
      
       Student student2 = new Student();
       student2.setTestScore(1, 10);
       student2.setTestScore(2, 30);
       student2.setTestScore(3, 32);
      
       System.out.println("-------------Student2-----------");
       System.out.println("Test Score 3: "+student2.getTestScore(3));
       System.out.println("Average is: "+student2.average());
       System.out.println(student2);
      
   }
}

Output

Answer 2:

Course.java

import java.util.ArrayList;
import java.util.List;

public class Course {

   private List<Student> students = new ArrayList<>();
   private String courseName;

   public Course(String courseName) {
       super();
       this.courseName = courseName;
   }

   public void addStudent(Student student) {
       this.students.add(student);
   }

   public int average() {
       int total = 0;
       for (Student student : this.students) {
           total += student.average();
       }
       return total / this.students.size();
   }

   public void roll() {
       for (Student student : this.students) {
           System.out.println(student);
       }
   }
}
Driver class CourseApp.java

package com.abc;

public class CourseApp {

   public static void main(String[] args) {
       Course course = new Course("Data Science");

       Student student1 = new Student(20, 30, 40);
       Student student2 = new Student(26, 22, 29);
       Student student3 = new Student(19, 45, 46);
       Student student4 = new Student(34, 33, 41);
       Student student5 = new Student(39, 41, 36);

       course.addStudent(student1);
       course.addStudent(student2);
       course.addStudent(student3);
       course.addStudent(student4);
       course.addStudent(student5);

       course.roll();
       System.out.println("All student average is: " + course.average());
   }
}

Output:

Answer 3:

I have created 4 classes Book.java, Novel.java , BookApp.java and NovelApp.java.

Book.java

import java.util.Date;

public class Book {

   private String bookName;
   private String ISBNNumber;
   private String author;
   private double price;
   private int totalPages;
   private Date publishedDate;

   public Book(String bookName, String ISBNNumber, String author, double price, int totalPages, Date publishedDate) {
       super();
       this.bookName = bookName;
       this.ISBNNumber = ISBNNumber;
       this.author = author;
       this.price = price;
       this.totalPages = totalPages;
       this.publishedDate = publishedDate;
   }

   public double getPrice() {
       return price;
   }

   public void setPrice(double price) {
       this.price = price;
   }

   public String getBookName() {
       return bookName;
   }

   public String getISBNNumber() {
       return ISBNNumber;
   }

   public String getAuthor() {
       return author;
   }

   public int getTotalPages() {
       return totalPages;
   }

   public Date getPublishedDate() {
       return publishedDate;
   }

   @Override
   public String toString() {
       return "Book [bookName=" + bookName + ", ISBNNumber=" + ISBNNumber + ", author=" + author + ", price=" + price
               + ", totalPages=" + totalPages + ", publishedDate=" + publishedDate + "]";
   }

}
BookApp.java

import java.util.Date;

public class BookApp {

   public static void main(String[] args) {
       Book myBook = new Book("Effective Java", "98-345-678-123", "Joshua Bloch", 10.00, 412, new Date());
      
       myBook.setPrice(25.00);
       System.out.println("Book name is: "+myBook.getBookName());
       System.out.println("Book author is: "+myBook.getAuthor());
       System.out.println("Book price is: "+myBook.getPrice());
       System.out.println("ISBN is: "+myBook.getISBNNumber());
       System.out.println("Total pages are: "+myBook.getTotalPages());
      
       System.out.println(myBook);
   }
}

Output


Novel.java

import java.util.ArrayList;
import java.util.List;

public class Novel {

   private String novelName;
   private String novelCategory;
   private String author;
   private double price;
   private int totalPages;
   private List<String> mainCharacters = new ArrayList<>();

   public Novel(String novelName, String novelCategory, String author, int totalPages) {
       super();
       this.novelName = novelName;
       this.novelCategory = novelCategory;
       this.author = author;
       this.totalPages = totalPages;
   }

   public double getPrice() {
       return price;
   }

   public void setPrice(double price) {
       this.price = price;
   }

   public String getNovelName() {
       return novelName;
   }

   public String getNovelCategory() {
       return novelCategory;
   }

   public int getTotalPages() {
       return totalPages;
   }

   public void addMainCharacter(String characterName) {
       this.mainCharacters.add(characterName);
   }

   public List<String> getMainCharacters() {
       return this.mainCharacters;
   }

   public String getAuthor() {
       return author;
   }

   @Override
   public String toString() {
       return "Novel [novelName=" + novelName + ", novelCategory=" + novelCategory + ", author=" + author + ", price="
               + price + ", totalPages=" + totalPages + ", mainCharacters=" + mainCharacters + "]";
   }

}
NovelApp.java

public class NovelApp {

   public static void main(String[] args) {
       Novel novel = new Novel("Catch-22", "Absurdist fiction", "Joseph Heller", 453);
       novel.addMainCharacter("Yossarian");
       novel.addMainCharacter("Scheisskopf");
       novel.addMainCharacter("Colonel Cathcart");
      
       novel.setPrice(10.00);
      
       System.out.println("Novel name is: "+novel.getNovelName());
       System.out.println("Novel author is: "+novel.getAuthor());
       System.out.println("Novel price is: "+novel.getPrice());
       System.out.println(novel);
      
   }
}
Output

Answer 4:

Question is not quite clear to me as lot of details are missing like Executive class I'm not able to figure out the exact data members from the data. Hence my answer is based on the assumption.

Assuming Executive class has the field for classification as follows:

public class Executive {

   private String classification;
   private String vacationOptionOne;
   private String vacationOptionTwo;
   private String vacationOptionThree;
   private int vacationDays = 14;

   public String getVacationOption(String classification) {
       if (classification.equals("class1")) {
           return vacationOptionOne;
       } else if (classification.equals("class2")) {
           return vacationOptionTwo;
       }
       return vacationOptionThree;
   }

   public int vacation() {
       return vacationDays;
   }
  
   public void setVacationDays(int vacationDays) {
       this.vacationDays = vacationDays;
   }

}
you can also initialize vacationDyas into a constructor. Due to unavailability of information I have not provided the driver class for this. The getVacationOption(String classification) method will return the vacation option based on the classification.

Please mention your doubts in the comment will be happy to clarify it.

Add a comment
Know the answer?
Add Answer to:
please use java do what u can 1. Modify the Student class presented to you as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a class called Course_xxx that represents a course taken at a school. Represent each student...

    Write a class called Course_xxx that represents a course taken at a school. Represent each student using the Student class from the Chapter 7 source files, Student.java. Use an ArrayList in the Course to store the students taking that course. The constructor of the Course class should accept only the name of the course. Provide a method called addStudent that accepts one Student parameter. Provide a method called roll that prints all students in the course. Create a driver class...

  • In Java: Develop a simple class for a Student. Include class variables; StudentID (int), FirstName, LastName,...

    In Java: Develop a simple class for a Student. Include class variables; StudentID (int), FirstName, LastName, GPA (double), and Major. Extend your class for a Student to include classes for Graduate and Undergraduate. o Include a default constructor, a constructor that accepts the above information, and a method that prints out the contents FOR EACH LEVEL of the object, and a method that prints out the contents of the object. o Write a program that uses an array of Students...

  • Given a class called Student and a class called Course that contains an ArrayList of Student....

    Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called getDeansList() as described below. Refer to Student.java below to learn what methods are available. I will paste both of the simple .JAVA codes below COURSE.JAVA import java.util.*; import java.io.*; /****************************************************** * A list of students in a course *****************************************************/ public class Course{     /** collection of Students */     private ArrayList<Student> roster; /***************************************************** Constructor for objects of class Course *****************************************************/...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • In Java programming language Please write code for the 6 methods below: Assume that Student class...

    In Java programming language Please write code for the 6 methods below: Assume that Student class has name, age, gpa, and major, constructor to initialize all data, method toString() to return string reresentation of student objects, getter methods to get age, major, and gpa, setter method to set age to given input, and method isHonors that returns boolean value true for honors students and false otherwise. 1) Write a method that accepts an array of student objects, and n, the...

  • 1. Do the following a. Write a class Student that has the following attributes: - name:...

    1. Do the following a. Write a class Student that has the following attributes: - name: String, the student's name ("Last, First" format) - enrollment date (a Date object) The Student class provides a constructor that saves the student's name and enrollment date. Student(String name, Date whenEnrolled) The Student class provides accessors for the name and enrollment date. Make sure the class is immutable. Be careful with that Date field -- remember what to do when sharing mutable instance variables...

  • please help Write a simple program with Student class having STL list of Record's structure as...

    please help Write a simple program with Student class having STL list of Record's structure as a member. 1. Records of the Students are not accessible to the outside world. 2. Student shall output its standing (Freshman, Sophomore etc). 3. A Student can only be created with the name 4. A class can only be added if there is a class name and the passing grade. Driver program creates a Student, adds few classes to the Student's records, then prints...

  • Create a java class for an object called Student which contains the following private attributes: a...

    Create a java class for an object called Student which contains the following private attributes: a given name (String), a surname (family name) (String), a student ID number (an 8 digit number, String or int) which does not begin with 0. There should be a constructor that accepts two name parameters (given and family names) and an overloaded constructor accepting two name parameters and a student number. The constructor taking two parameters should assign a random number of 8 digits....

  • JAVA HELP FOR COMP: Can someone please modify the code to create LowestGPA.java that prints out...

    JAVA HELP FOR COMP: Can someone please modify the code to create LowestGPA.java that prints out the name of the student with the lowestgpa. In the attached zip file, you will find two files HighestGPA.java and students.dat. Students.dat file contains names of students and their gpa. Check if the code runs correctly in BlueJ or any other IDE by running the code. Modify the data to include few more students and their gpa. import java.util.*; // for the Scanner class...

  • JAVA /** * This class stores information about an instructor. */ public class Instructor { private...

    JAVA /** * This class stores information about an instructor. */ public class Instructor { private String lastName, // Last name firstName, // First name officeNumber; // Office number /** * This constructor accepts arguments for the * last name, first name, and office number. */ public Instructor(String lname, String fname, String office) { lastName = lname; firstName = fname; officeNumber = office; } /** * The set method sets each field. */ public void set(String lname, String fname, String...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT