CS 212 Assignment 3 1. Write a user-defined class, Sphere, which includes one instance variable, radius, and following instance methods, set, area, volume and writeOutput. Then write the driver code...

1 answer below »
C:\Users\Charles Broderick\Documents\M3_Assignments (1).docx


CS 212 Assignment 3 1. Write a user-defined class, Sphere, which includes one instance variable, radius, and following instance methods, set, area, volume and writeOutput. Then write the driver code to use the Sphere class. Requirements, in the driver, prompt a message and let the user input the radius, and then output its surface area and volume to the monitor by calling the writeOutput method, display the results to one decimal place. Use a loop in the driver, so the process could go continuously. 2. Write a user defined class, Programmer, which includes instance variables, name and workingYears, and following instance methods, set, salary and writeOuput. Assume that the salary (S) will increase $3000 per year (Y) of work, plus a base of $42,000, meaning, S = 42000+3000*Y. Then write a driver class to use the Programmer class, prompting a message for the user to keyboard-input the information of a programmer, and output his/her name and salary to the monitor by invoking the writeOuput method. Use a loop in the driver, so the process could go continuously. 3. Write a user-defined class, Student, which includes three instance variables, name, test1 and test2, constructor(s), as well as instance methods, including set, average, grade and writeOutput. Write the driver code to use the Student class, prompting a message for the user to keyboard-input the name and two test scores of a student, and output that student’s information including name, average and grade (“A”, “B”, .., “F”) to the monitor by invoking the writeOuput method. Use a loop in the driver, so the process could go continuously. Page 1 of 1 Page 2 of 1
Answered Same DayJul 24, 2021

Answer To: CS 212 Assignment 3 1. Write a user-defined class, Sphere, which includes one instance variable,...

Neha answered on Jul 24 2021
156 Votes
88498 - java codes/question 1/Main.java
88498 - java codes/question 1/Main.java
import java.util.*;
public class Main{
    public static vo
id main(String[] args)
    {
        int radius;
        Sphere sp = new Sphere();
        Scanner sc= new Scanner(System.in);
        do
        { 
            System.out.print("Enter radius: ");
            radius = sc.nextInt();
            sp.set(radius);
            System.out.print(sp.writeOutput());
        }while(radius > 0);
    }
}
88498 - java codes/question 1/Sphere.java
88498 - java codes/question 1/Sphere.java
public class Sphere {
    private int radius;
    static float pi = 3.14159f;
    public void set(int radius)
    {
        this.radius = radius;
    }
    public float volume(int radius)
    {
        float vol;
        vol = ((float)4 / (float)3) * (pi * radius * radius * radius);
        return vol;
    }
    public float area(int radius)
    {
        float sur_ar;
        sur_ar = 4 * pi * radius * radius;
        return sur_ar;
    }
    public String writeOutput()
    {
        float sur_area, vol;
        String rad = Integer.toString(radius);
        sur_area = area(radius);
        vol = volume(radius);
        return "Radius: " + rad + "\n" + "Area: " + String.format("%.1f", sur_area) + "\n" + "Volume: " + String.format("%.1f", vol) + "\t";
    }
}
88498 - java codes/question 2/Main.java
88498 - java...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here