Question

In: Computer Science

I am having an issue with the code. The issue I am having removing the part...

I am having an issue with the code. The issue I am having removing the part when it asks the tuter if he would like to do teach more. I want the program to stop when the tuter reaches 40 hours. I believe the issue I am having is coming from the driver.

Source Code:

Person .java File:


public abstract class Person {
private String name;

/**
* Constructor
* @param name
*/
public Person(String name) {
super();
this.name = name;
}

/**
* @return the name
*/
public String getName() {
return name;
}

/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "Name: " + name;
}
  
  
}

**************************************************************************************

Student .java File:


public class Student extends Person {
private int age;
private Tuter tuter;
/**
* @param name
* @param age
* @param tuter
*/
public Student(String name, int age, Tuter tuter) {
super(name);
this.age = age;
this.tuter = tuter;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
/**
* @return the tuter
*/
public Tuter getTuter() {
return tuter;
}
/**
* @param tuter the tuter to set
*/
public void setTuter(Tuter tuter) {
this.tuter = tuter;
}
  
private double getDiscountAmount() {
// Calculate discount rate
double discountRate = 0;
if(this.age < 10) {
discountRate = 20;
}
  
return tuter.getTotalDue() * discountRate / 100;
}
  
@Override
public String toString() {
return "Student Name: " + super.getName() + "\nAge: " + age;
}
  
public void printInvoice() {
// Print student info
System.out.println(this.toString());
  
// Print tuter information
System.out.println(tuter.toString());
  
// print the invoices details
System.out.printf("Rate per Hour: $%.2f\n", tuter.getRatePerHour());
System.out.println("Hours of Instruction: " + tuter.getHoursOfInstrction());
  
//Print the discount applied
System.out.printf("Discount applied: $%.2f\n", this.getDiscountAmount());
System.out.printf("Total Due : $%.2f\n", (tuter.getTotalDue() - this.getDiscountAmount()));
}
}

**************************************************************************************

Tuter.java File:


public class Tuter extends Person{
private int hoursOfInstrction;
private double ratePerHour;
private final static int MAX_HOURS = 30;
public Tuter(String name) {
super(name);
this.hoursOfInstrction = 0;
this.ratePerHour = 10.00;
}
/**
* @return the hoursOfInstrction
*/
public int getHoursOfInstrction() {
return hoursOfInstrction;
}

/**
* @param hours the hoursOfInstrction to set
*/
public boolean addHoursOfInstrction(int hours) {
if(this.hoursOfInstrction + hours <= MAX_HOURS) {
this.hoursOfInstrction+= hours;
return true;
}else
return false;
}

  
public double getRatePerHour() {
return ratePerHour;
}


public void setRatePerHour(double ratePerHour) {
this.ratePerHour = ratePerHour;
}
  
  
public double getTotalDue() {
return this.getRatePerHour() * this.getHoursOfInstrction();
}

@Override
public String toString() {
return "Tuter Name: " + super.getName();
}
}

**************************************************************************************

Driver .java File


public class Driver {

public static void main(String[] args) {
//Create a Tuter object
Tuter tuter = new Tuter("Sara");
// Create a Student object and assign the tuter
Student student = new Student("Mai Do", 19, tuter);
int hours;
Scanner scan = new Scanner(System.in);
String choice;
do {
System.out.println("Enter the amount of hours:");
hours = scan.nextInt();
//If tuter can teach more
if(tuter.addHoursOfInstrction(hours)) {
System.out.println("Do you want to teach more? yes/no");
choice = scan.next();
}else
break;
}while(choice.equals("yes"));
  
student.printInvoice();

System.out.println("Another tuter:");

}
}

**************************************************************************************

Solutions

Expert Solution

Solution: HI............ TRY THIS.........


import java.util.Scanner;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author VIDYA
*/

abstract class Person {
private String name;

/**
* Constructor
* @param name
*/
public Person(String name) {
super();
this.name = name;
}

/**
* @return the name
*/
public String getName() {
return name;
}

/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "Name: " + name;
}
  
  
}


class Student extends Person {
private int age;
private Tuter tuter;
/**
* @param name
* @param age
* @param tuter
*/
public Student(String name, int age, Tuter tuter) {
super(name);
this.age = age;
this.tuter = tuter;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
/**
* @return the tuter
*/
public Tuter getTuter() {
return tuter;
}
/**
* @param tuter the tuter to set
*/
public void setTuter(Tuter tuter) {
this.tuter = tuter;
}
  
private double getDiscountAmount() {
// Calculate discount rate
double discountRate = 0;
if(this.age < 10) {
discountRate = 20;
}
  
return tuter.getTotalDue() * discountRate / 100;
}
  
@Override
public String toString() {
return "Student Name: " + super.getName() + "\nAge: " + age;
}
  
public void printInvoice() {
// Print student info
System.out.println(this.toString());
  
// Print tuter information
System.out.println(tuter.toString());
  
// print the invoices details
System.out.printf("Rate per Hour: $%.2f\n", tuter.getRatePerHour());
System.out.println("Hours of Instruction: " + tuter.getHoursOfInstrction());
  
//Print the discount applied
System.out.printf("Discount applied: $%.2f\n", this.getDiscountAmount());
System.out.printf("Total Due : $%.2f\n", (tuter.getTotalDue() - this.getDiscountAmount()));
}
}

class Tuter extends Person{
private int hoursOfInstrction;
private double ratePerHour;
final static int MAX_HOURS = 30;
public Tuter(String name) {
super(name);
this.hoursOfInstrction = 0;
this.ratePerHour = 10.00;
}
/**
* @return the hoursOfInstrction
*/
public int getHoursOfInstrction() {
return hoursOfInstrction;
}

/**
* @param hours the hoursOfInstrction to set
*/
public boolean addHoursOfInstrction(int hours) {
if(this.hoursOfInstrction + hours <= MAX_HOURS) {
this.hoursOfInstrction+= hours;
return true;
}else
return false;
}

  
public double getRatePerHour() {
return ratePerHour;
}


public void setRatePerHour(double ratePerHour) {
this.ratePerHour = ratePerHour;
}
  
  
public double getTotalDue() {
return this.getRatePerHour() * this.getHoursOfInstrction();
}

@Override
public String toString() {
return "Tuter Name: " + super.getName();
}
}

public class hours {

public static void main(String[] args) {
//Create a Tuter object
Tuter tuter = new Tuter("Sara");
// Create a Student object and assign the tuter
Student student = new Student("Mai Do", 19, tuter);
int hours;
Scanner scan = new Scanner(System.in);
String choice;
do
{
System.out.println("Enter the amount of hours:");
hours = scan.nextInt();
//If tuter can teach more
if(tuter.addHoursOfInstrction(hours)){
System.out.println("Do you want to teach more? yes/no");
choice = scan.next();
}
else
{
System.out.println("Oooops...!!! Your hours are exceeded");

student.printInvoice();

System.out.println("Another tuter:");

System.exit(0);
}
}while(tuter.addHoursOfInstrction(hours)==false);  

}
}

OUTPUT:


Related Solutions

I have the following code for my java class assignment but i am having an issue...
I have the following code for my java class assignment but i am having an issue with this error i keep getting. On the following lines: return new Circle(color, radius); return new Rectangle(color, length, width); I am getting the following error for each line: "non-static variable this cannot be referenced from a static context" Here is the code I have: /* * ShapeDemo - simple inheritance hierarchy and dynamic binding. * * The Shape class must be compiled before the...
I am having trouble with a C++ code that I'm working on. It is a spell...
I am having trouble with a C++ code that I'm working on. It is a spell checker program. It needs to compare two arrays, a dictionary, and an array with misspelled strings that are compared to the strings in the dictionary. the strings that are in the second array that is not in the Dictionary are assumed to be misspelled. All of the strings in the dictionary are lowercase without any extra characters so the strings that are passed into...
I am having an issue with the Java program with a tic tac toe. it isn't...
I am having an issue with the Java program with a tic tac toe. it isn't a game. user puts in the array and it prints out this. 1. Write a method print that will take a two dimensional character array as input, and print the content of the array. This two dimensional character array represents a Tic Tac Toe game. 2. Write a main method that creates several arrays and calls the print method. Below is an example of...
I am having problems getting the second button part of this to work. this is for...
I am having problems getting the second button part of this to work. this is for visual basic using visual studio 2017. Please help. Create an application named You Do It 4 and save it in the VB2017\Chap07 folder. Add two labels and two buttons to the form. Create a class-level variable named strLetters and initialize it to the first 10 uppercase letters of the alphabet (the letters A through J). The first button’s Click event procedure should use the...
I am currently having trouble understanding/finding the errors in this python code. I was told that...
I am currently having trouble understanding/finding the errors in this python code. I was told that there are 5 errors to fix. Code: #!/usr/bin/env python3 choice = "y" while choice == "y": # get monthly investment monthly_investment = float(input(f"Enter monthly investment (0-1000):\t")) if not(monthly_investment > 0 and monthly_investment <= 100): print(f"Entry must be greater than 0 and less than or equal to 1000. " "Please start over.")) #Error 1 extra ")" continue # get yearly interest rate yearly_interest_rate = float(input(f"Enter...
hello, I am having an issue with a question in my highway engineering course. the question...
hello, I am having an issue with a question in my highway engineering course. the question is: An equal tangent sag vertical curve has an initial grade of –2.5%. It is known that the final grade is positive and that the low point is at elevation 82 m and station 1 + 410.000. The PVT of the curve is at elevation 83.5 m and the design speed of the curve is 60 km/h. Determine the station and elevation of the...
Using dev c++ I'm having trouble with classes. I think the part that I am not...
Using dev c++ I'm having trouble with classes. I think the part that I am not understanding is sending data between files and also using bool data. I've been working on this program for a long time with many errors but now I've thrown in my hat to ask for outside help. Here is the homework that has given me so many issues: The [REDACTED] Phone Store needs a program to compute phone charges for some phones sold in the...
Please fix this code I am having issues compiling it all together there is 3 codes...
Please fix this code I am having issues compiling it all together there is 3 codes here and it's giving me errors in my main method..... I feel like it might be something simple but I can't seem to find it. package assignement2; import java.util.ArrayList; import java.util.Scanner; public class reg1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the number of items: "); int number = input.nextInt(); input.nextLine(); for (int i = 0; i <...
I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
I am given this starter code and I am suppose to debug it and all of...
I am given this starter code and I am suppose to debug it and all of that and it will not work after I change ">" to "<=" and then i'm not sure after that what else I have to do. Could someone help me solve this? // Start with a penny // double it every day // how much do you have in a 30-day month? public class DebugSix1 {    public static void main(String args[])    {      ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT