Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete a programming challenge (other than programming challenge 1) from the e

ID: 3854687 • Letter: C

Question

Complete a programming challenge (other than programming challenge 1) from the end of chapter 11. Remember to include commenting and formatting (e.g. indenting) consistent with the chapter examples.

Q-1 Write a class named TestScores. The Class Constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate class in a Program.

Complete the Pseudocode (refresh from chapter 1) and the UML diagram (refresh from chapter 6) for a programming challenge (other than programming challenge 1) from the end of chapter 12.

Q-2 Joe's automotive perform the following routine maintance services:

oil change - $26.00

lube job - $18.00

Radiator flush - $30.00

Transmission flush - $80.00

Inspection - $15.00

Tire rotation - $20.00

Joe also perform other nonroutine service and charges for parts and for labor ($20 per hours). Create a GUI application that displays the total for a customer's visit to Joe's.

Explanation / Answer

the javaprogramming code is

import java.io.*;

import java.util.Scanner;

public class TestScores

{

public static void main(String[]args)

{

int numberofTests = 0;

double[] grade = new double[numberofTests];

double totalgrades = 0;

double average;

Scanner sc = new Scanner(System.in);

System.out.print("enter the number of tests: ");

numberofTests = sc.nextInt();

grade = new double[(int) numberofTests];

//for loop to enter test grades.

for (int index = 0; index < grade.length; index++)

{

System.out.print("Enter grade for Test " + (index + 1) + ": ");

grade[index] = sc.nextDouble();

if (grade[index] < 0 || grade[index] > 100)

{

throw new IllegalArgumentException(

"Invalid number used for test score");

}

}

for (int index = 0; index < grade.length; index++)

{

totalgrades += grade[index];

}

//average of grades.

average = totalgrades/grade.length;

System.out.print("The average is: " + average);

}

}

the output is:enter the number of tests: 5
Enter grade for Test 1: 68
Enter grade for Test 2: 78
Enter grade for Test 3: 65
Enter grade for Test 4: 98
Enter grade for Test 5: 84
The average is: 78.6

the output when we enter test grade above 100 is:

enter the number of tests: 5

Enter grade for Test 1: 78

Enter grade for Test 2: 86

Enter grade for Test 3: 567

Exception in thread "main" java.lang.IllegalArgumentException: Invalid number used for test score

at constructors.TestScores.main(TestScores.java:31)

Q-2)the java programming code is

//This is For the services part
import java.awt.*;
import javax.swing.*;
public class Service extends JPanel
{
// The following constants are used to indicate
// the cost of services for automotive.
public final double oilchange = 26.00;
public final double lubejob = 18.00;
public final double radiatorflush = 30.00;
public final double transmissionflush = 80.00;
public final double inspection= 15.00;
public final double mufflerreplacement = 100.00;
public final double tirerotation = 20.00;
// for text field.
private JTextField calcTextField;
// check boxes listed for the available services.
private JCheckBox oilchange;
private JCheckBox lubejob;
private JCheckBox radiatorflush;
private JCheckBox transmissionflush;
private JCheckBox inspection;
private JCheckBox mufflerreplacement;
private JCheckBox tirerotation;

// Constructor

public Service()
{

// gridlayout with seven rows and one column.
setLayout(new GridLayout(7,1 ));


// Create the check boxes.
oilchange = new JCheckBox("Oil Change ($26.00)");

lubejob = new JCheckBox("Lube Job ($18.00)");

radiatorflush = new JCheckBox("Radiator Flush ($30.00)");

transmissionflush = new JCheckBox("Transmission Flush ($80.00)");

inspection = new JCheckBox("Inspection ($15.00)");

mufflerreplacement = new JCheckBox("Muffler Replacement ($100.00)");

tirerotation = new JCheckBox("Tire Rotation ($20.00)");

// Add a border around the panel.
setBorder(BorderFactory.createTitledBorder("Routine Services"));

// Add the check boxes to this panel.

add(oilchange);

add(lubejob);

add(radiatorflush);

add(transmissionflush);

add(inspection);

add(mufflerreplacement);

add(tirerotation);
}

//This method returns the cost of the selected services.

public double actionCalculate()
{
double total = 0;
if(oilchange.isSelected())
total = total + oilchange;

if(lubejob.isSelected())
total = total + lubejob;

if(radiatorflush.isSelected())
total = total + radiatorflush;

if(transmissionflush.isSelected())
total = total + transmissionflush;

if(Inspection.isSelected())
total = total + inspection;

if(mufflerreplacement.isSelected())
total = total + mufflerreplacement;

if(tirerotation.isSelected())
total = total + tirerotation;
return total;

}
}

//This for NonRoutine Services
import java.awt.*;
import javax.swing.*;
public class NonService extends JPanel
{
public final double perhourcharge = 20.00; //per hour labor cost
private JLabel partslabel; //references parts charges label
private JLabel laborlabel; //references hours of labor label
private JTextField partsTextField; //references parts charges text field
private JTextField laborTextField; //references hours of labor text field
private JPanel panel;
public NonService()
{
//Create labels
partsLabel = new JLabel("Parts Charges:");
laborLabel = new JLabel("Hours of Labor:");

// Create the text Fields
partsTextField = new JTextField(10);
laborTextField = new JTextField(10);

// Add a border around the panel
setBorder(BorderFactory.createTitledBorder("Nonroutine services"));

add(partsLabel);
add(partsTextField);
add(laborLabel);
add(laborTextField);

panel = new JPanel();
panel.setLayout(new GridLayout(3,2));
setLayout(new GridLayout(2, 2));
}
}

//This calculates everthing and creates the GUI App

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;

//The CalculatorGUI class creates the GUI for joe's automotive application.

public class CalculatorGUI extends JFrame
{


// custom panel objects.

//services part.
private Service sc;
private NonService ns;


// The following variables will reference objects

private JPanel buttonPanel;
private JButton calcButton;
private JButton exitButton;



// Constructor

public CalculatorGUI()
{
// Display title.
super("Joe's Automotive");
setLocationRelativeTo(null);
// Specify an action for the close button.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Create a BorderLayout manager for
// the content pane.
setLayout(new BorderLayout());

// Create the custom panels.
sc = new Service();
ns = new NonService();


// Call the buildButtonPanel method to
// create the button panel.
buildButtonPanel();

// Add the components to the content pane.
add(sc, BorderLayout.NORTH);


add(ns, BorderLayout.SOUTH);

// Pack the contents of the window and display it.
pack();
setVisible(true);
}

//The buildbuttonpanel method builds the button panel.

private void buildButtonPanel()
{
// Create a panel for the buttons.
buttonPanel = new JPanel();

// Create the buttons.
calcButton = new JButton("Calculate Charges");
exitButton = new JButton("Exit");

// Register the action listeners.
calcButton.addActionListener(new CalcButtonListener());
exitButton.addActionListener(new ExitButtonListener());

// Add the buttons to the button panel.
buttonPanel.add(calcButton);
buttonPanel.add(exitButton);

}

// Private inner class that handles the event when the user clicks the Calculate button.

private class CalcButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{


double total; // The total of order

// Calculate the subtotal.
total = sc.actionCalculate() +
ns.getNonroutineServicesCost();

// creating a decimalformat object to format

DecimalFormat dollar = new DecimalFormat("0.00");

// Display the charges.
JOptionPane.showMessageDialog(null, "Total: $" +
dollar.format(total) );

}
}

// private inner class that handles the event when the user clicks the exit button.

private class ExitButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{

System.exit(0);
}
}
public static void main(String args[])

{

new CalculatorGUI();

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote