Question
For those who know Java: Below is my current java code for calculating the cost of tuition at a college. Directions: Write a program Tuition
For those who know Java: Below is my current java code for calculating the cost of tuition at a college.
Directions: Write a program Tuition to calculate and display the tuition and additional costs (textbooks and parking fee) a student should expect if he were to attend college. Write a method calculateTuition that calculates and returns tuition (based on number of credits and cost per credit,
Use the most appropriate data types for
Cost per credit
Parking fee
Total cost for books
and Number of credits per semester taken by the student. Here are the requirements I need:
1.Class name is Tuition(Project name could be TuitionProject)
2. Method name iscalculateTuition
3.Method has at least 2 parameters: number of credits and cost per credit
4.Parameters have descriptive names (ex, credits, costPerCredit, not a or b or a number) and are correct data types
5.Method declared as public, not private
6.JOptionPane.showInputDialog() method is used for input credits and cost per credit. You can optionally use JTextField for input if you prefer
7.The output must be formatted to 2 decimals. It is not enough to choose numbers that would be automatically displayed with 2 decimals. The program should work correctly with any valid data and should be displayed in the frame (do not use the JOptionPane.showMessageDialog method for the output.
Did I do everything correct? Could someone edit my mistakes and to check and see how I could display textbook costs in this calculator. ALSO can someone show me how to put a logo image by "North Hennepin Community College" in the program?
import java.text.DecimalFormat;
import javax.swing.JOptionPane;
public class TuitionCost {
public static void main(String[] args) { int costCredits; int student; String input; double a;
DecimalFormat dollar = new DecimalFormat("#,##0.00");
JOptionPane.showMessageDialog(null, "North Hennepin Community College", "Tuition Costs at OCC", JOptionPane.INFORMATION_MESSAGE); input = JOptionPane.showInputDialog(null, "Are you taking: 1 - on-campus and/or hybrid courses 2 - online courses Please enter 1 or 2:", "Input", JOptionPane.QUESTION_MESSAGE); double[] rates = {184.17,193.85}; student = Integer.parseInt(input);
if(student > 0 && student < 4){ input = JOptionPane.showInputDialog(null, "How many credits are you taking?", JOptionPane.QUESTION_MESSAGE); costCredits = Integer.parseInt(input); if(costCredits != 0){ a = costCredits * rates[student]; JOptionPane.showMessageDialog(null, dollar.format(costCredits) + " credits at $" + rates[student] + " per semester yields a tuition of $" + dollar.format(a)); }else{ JOptionPane.showMessageDialog(null, "Credits cannot be zero.", "Invalid Input", JOptionPane.ERROR_MESSAGE); } System.exit(0); }else { JOptionPane.showMessageDialog(null, "You must enter a 1 or 2. Please Run the program again.", "Invalid Input", JOptionPane.ERROR_MESSAGE); } } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started